django-admin 隐藏或禁用按钮

1.屏蔽添加按钮:
def has_add_permission(self,request): 
  return False
2.屏蔽自定义按钮
如果不是超级管理员或者不是运营部的,则不显示对应的自定义按钮
def get_actions(self, request):
  actions = super().get_actions(request)
   if not (request.user.is_superuser or request.user.groups.filter(name="运营部")):
     if 'custom_button' in actions:
       del actions['custom_button']
   return actions
posted @ 2023-03-23 13:05  super_ip  阅读(164)  评论(0编辑  收藏  举报