django admin 列表禁用删除操作,编辑页面禁用删除按钮

2023-02-18 14:28:51 浏览数 (1)

代码语言:javascript复制
class AnchorBindAgentAdmin(admin.ModelAdmin):

    def get_actions(self, request):
        # 列表禁用删除操作
        if 'delete_selected' in actions:
            del actions['delete_selected']
        return actions

    def has_delete_permission(self, request, obj=None):
        # 编辑页面禁用删除按钮
        return False

0 人点赞