Reputation: 71
How to modify default admin action "delete_selected"
Upvotes: 6
Views: 2492
Reputation: 441
Disabling a site-wide action
admin.site.disable_action('delete_selected')
Otherwise override ModelAdmin.get_actions
Upvotes: 0
Reputation: 39287
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
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