Remove the default delete action in Django admin

How to remove the default delete action in Django admin? Would the following work?

actions = [ ] 

This works:

def get_actions(self, request):
    actions = super().get_actions(request)
    if 'delete_selected' in actions:
        del actions['delete_selected']
    return actions

It's also the recommended way to do this based off Django's documentation below:

Conditionally enabling or disabling actions


In your admin class, define has_delete_permission to return False:

class YourModelAdmin(admin.ModelAdmin):
    ...

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

Then, it will not show delete button, and will not allow you to delete objects in admin interface.


You can disable "delete selected" action site-wide:

from django.contrib.admin import site
site.disable_action('delete_selected')

When you need to include this action, add 'delete_selected' to the action list:

actions = ['delete_selected']

Documentation


If you want to remove all the action:

class UserAdmin(admin.ModelAdmin):
    model = User
    actions = None

If you want some specific action:

class UserAdmin(admin.ModelAdmin):
    model = User
    actions = ['name_of_action_you_want_to_keep']