如图:
如果要移除默认的 delete_selected 操作,可以通过重写 get_actions 方法实现。
class MyModelAdmin(admin.ModelAdmin):
...
# 所有用户都不可见
def get_actions(self, request):
actions = super().get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
return actions
# 针对某个特定的用户不可见
def get_actions(self, request):
actions = super().get_actions(request)
if request.user.username[0].upper() != 'J':
if 'delete_selected' in actions:
del actions['delete_selected']
return actions
关注公众号「Python之禅」,回复「1024」免费获取Python资源