Dmitriy
Dmitriy

Reputation: 71

modify admin actions

How to modify default admin action "delete_selected"

Upvotes: 6

Views: 2492

Answers (3)

xavierskip
xavierskip

Reputation: 441

DOC:Disabling actions

Disabling a site-wide action

admin.site.disable_action('delete_selected')

Otherwise override ModelAdmin.get_actions

Upvotes: 0

dting
dting

Reputation: 39287

Action docs

delete selected:

If you wish to override this behavior, simply write a custom action which accomplishes deletion in your preferred manner – for example, by calling Model.delete() for each of the selected items.

This discussion has an example of overriding 'delete_selected' for a model. It could be implemented like this:

class SomeModelAdmin(admin.ModelAdmin):
    actions = ['custom_delete_selected']
    def custom_delete_selected(self, request, queryset):
         #custom delete code
    custom_delete_selected.short_description = "Delete selected items"

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

Upvotes: 14

Timmy O'Mahony
Timmy O'Mahony

Reputation: 53981

http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#adding-actions-to-the-modeladmin

You can write custom actions, so overwriting the delete_selected action will allow you to carry out whatever functionality you need (see the warning box on the top of the page which mentions overwriting the delete() action)

Upvotes: 2

Related Questions