【Django Admin】 二次开发-权限
作者:互联网
# 判断 动态返回显示字段 self.list_display = ('name', 'head_picture', 'sex', 'interest', 'is_staff', 'age', 'score_custom', 'time', 'date') def get_list_display(self, request): if not request.user.is_superuser: res_list_display = ('name', 'head_picture', 'interest', 'is_staff', 'age', 'score_custom', 'time', 'date') else: res_list_display = self.list_display return res_list_display # 判断 动态限制搜索字段 self.list_filter = ('sex', 'is_staff', 'date') def get_list_filter(self, request): return self.list_filter # 判断 动态限制返回的自定义按钮 def get_actions(self, request): actions = super(UserInfoAdmin, self).get_actions(request) if request.user.is_superuser: # 删除 限制的自定义按钮 if 'action_demo' in actions: del actions['action_demo'] return actions # 处理每一行的所有数据 def get_results(self, results, request, queryset): new_results = [] for item in results: # 这里可以对结果进行干预,item是 dict类型 # print("item",item) pass new_results.append(item) return new_results
标签:Admin,request,self,list,results,actions,Django,二次开发,display 来源: https://www.cnblogs.com/wanghong1994/p/16425415.html