Change admin actions

How to change the default admin action "delete_selected"

+6
source share
3 answers

Action docs

delete selected:

If you want to override this behavior, simply write a custom action that performs the deletion in your preferred way - for example, by calling Model.delete () for each of the selected elements.

This discussion has an example of overriding 'delete_selected' for a model. It can be implemented as follows:

 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 
+13
source

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

You can write custom actions, so rewriting the delete_selected action will allow you to perform any necessary functionality (see the warning at the top of the page that mentions rewriting the delete () action)

+2
source

DOC: Disabling Actions

Disable action across the site

admin.site.disable_action('delete_selected')

Otherwise, override ModelAdmin.get_actions

0
source

Source: https://habr.com/ru/post/885480/


All Articles