In Django Admin how do I disable the Delete link

前端 未结 7 2236
天命终不由人
天命终不由人 2020-12-07 22:29

I\'ve managed to disable the \"Delete selected\" action. Easy.

But a user can still click on an item and then there\'s the red Delete link at the bottom.

7条回答
  •  离开以前
    2020-12-07 23:02

    The solutions here are already nice, but I prefer to have it as a reusable mixin, like this:

    class NoDeleteAdminMixin:
        def has_delete_permission(self, request, obj=None):
            return False
    

    You can use this in all your admins where you want to prevent deletion like this:

    class MyAdmin(NoDeleteAdminMixin, ModelAdmin):
        ...
    

提交回复
热议问题