首页 > 其他分享 >django-admin 隐藏或禁用按钮

django-admin 隐藏或禁用按钮

时间:2023-03-23 13:23:22浏览次数:45  
标签:自定义 admin self request actions django 运营部 按钮

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

标签:自定义,admin,self,request,actions,django,运营部,按钮
From: https://www.cnblogs.com/superip/p/17247080.html

相关文章