Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modify admin actions

Tags:

django

How to modify default admin action "delete_selected"

like image 591
Dmitriy Avatar asked Apr 08 '11 07:04

Dmitriy


1 Answers

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 
like image 164
dting Avatar answered Oct 11 '22 13:10

dting