def get_list_editable(self, request):
group_names = self.get_group_names(request.user)
if request.user.is_superuser or 'hr' in group_names:
return self.default_list_editable
return ()
django 不会主动调用 get_list_editable,需要在 get_changelist_instance 中覆盖
def get_changelist_instance(self, request):
# 覆盖父类 获取 list_editable 的方法
self.list_editable = self.get_list_editable(request)
return super(CandidateAdmin, self).get_changelist_instance(request)