使用Wagtails Modeladmin:
有没有办法禁用编辑&删除选项只留下检查视图?
我能想到的一种可能的方法是扩展模板,删除编辑和放大。删除按钮,然后以某种方式禁用编辑和删除视图。
有没有更清洁的方法?
编辑:感谢Loic回答,我可以理解。 PermissionHelper
source code对于确定要覆盖的正确方法也非常有帮助。
仅显示检查视图的完整答案
class ValidationPermissionHelper(PermissionHelper):
def user_can_list(self, user):
return True
def user_can_create(self, user):
return False
def user_can_edit_obj(self, user, obj):
return False
def user_can_delete_obj(self, user, obj):
return False
class ValidationAdmin(ModelAdmin):
model = Validation
permission_helper_class = ValidationPermissionHelper
inspect_view_enabled = True
[...]
答案 0 :(得分:2)
可悲的是,您需要add
change
,delete
或ModelAdmin
该模型的权限(在角色中设置)才能显示。
解决方法是为class MyPermissionHelper(wagtail.contrib.modeladmin.helpers.PermissionHelper):
def user_can_list(self, user):
return True # Or any logic related to the user.
class MyModelAdmin(wagtail.contrib.modeladmin.options.ModelAdmin):
model = MyModel
permission_helper_class = MyPermissionHelper
modeladmin_register(wagtail.contrib.modeladmin.options.MyModelAdmin)
提供at least one并始终允许列表(并且仍然允许在角色中设置添加/更改/删除):
typedef struct Student{
char* firstName;
char* lastName;
int priority;
int readingLevel;
bookIds* wishlist;
struct Student* next;
}student;
student* buildStudentList(char* studentsFile, student* head)
{
int i;
FILE* fp;
student* tempPtr = NULL;
if((fp = fopen(studentsFile, "r")) == NULL)
{
printf("Unable to open file\n");
return 0;
}
student* current = NULL;
tempPtr = (student*)malloc(sizeof(student));
tempPtr->firstName = malloc(sizeof(char)* NAME);
tempPtr->lastName = malloc(sizeof(char)* NAME);
while(fscanf(fp, "%s %s %d %d",tempPtr->firstName, tempPtr->lastName, tempPtr->priority, tempPtr->readingLevel) != EOF)
{
tempPtr->next = NULL;
if(head == NULL)
{
head = tempPtr;
current = tempPtr;
tempPtr = (student*)malloc(sizeof(student));
}
else
{
current->next = tempPtr;
current = tempPtr;
tempPtr = (student*)malloc(sizeof(student));
}
}
free(tempPtr);
fclose(fp);
return head;
}