Created
April 17, 2014 08:14
-
-
Save stefanfoulis/10963689 to your computer and use it in GitHub Desktop.
no-bulk-delete django admin action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NoBulkDeleteAdmin(admin.ModelAdmin): | |
def get_actions(self, request): | |
actions = super(NoBulkDeleteAdmin, self).get_actions(request) | |
del actions['delete_selected'] | |
actions['delete_selected'] = ( | |
NoBulkDeleteAdmin.no_bulk_delete, | |
'delete_selected', | |
'Delete Selected instances and delete docker instances.' | |
) | |
return actions | |
def no_bulk_delete(self, request, queryset): | |
n = 0 | |
for obj in queryset: | |
obj.delete() | |
n += 1 | |
self.message_user(request, "Successfully deleted %(count)d %(items)s." % { | |
"count": n, "items": model_ngettext(self.opts, n) | |
}, messages.SUCCESS) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment