Skip to content

Instantly share code, notes, and snippets.

@stefanfoulis
Created April 17, 2014 08:14
Show Gist options
  • Save stefanfoulis/10963689 to your computer and use it in GitHub Desktop.
Save stefanfoulis/10963689 to your computer and use it in GitHub Desktop.
no-bulk-delete django admin action
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