标签:set sharp edit 访问权限 pre tail 的区别 student 用户角色
xadmin中的用法:
class NewCourseAdmin:
list_display = [‘name‘, ‘detail‘, ‘degree‘, ‘learn_times‘, ‘students‘]
list_editable = [‘degree‘, ‘desc‘]
def queryset(self):
qs = super().queryset()
if not self.request.user.is_superuser:
qs = qs.filter(teacher=self.request.user.teacher)
return qs
xadmin.site.register(Course, NewCourseAdmin)
admin中的用法:
class NewCourseAdmin(admin.ModelAdmin):
list_display = [‘name‘, ‘detail‘, ‘degree‘, ‘learn_times‘, ‘students‘]
list_editable = [‘degree‘, ‘desc‘]
def get_queryset(self,request):
qs = super().get_queryset(request)
if not self.request.user.is_superuser:
qs = qs.filter(teacher=self.request.user.teacher)
return qs
admin.site.register(Course, NewCourseAdmin)
注意两者的区别
标签:set sharp edit 访问权限 pre tail 的区别 student 用户角色
原文地址:https://www.cnblogs.com/xiaohaodeboke/p/12815410.html