From 05a856e8418f4ac3ca11bf30a9b489252c631d00 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Tue, 26 Jun 2012 15:14:52 +0200 Subject: [PATCH] Override builting delete_selected action with one that does notifies This should fix the problem where notifications weren't sent for objects being deleted through the "mass deletion" function in the list of objects. Closes #121 --- pgweb/util/admin.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pgweb/util/admin.py b/pgweb/util/admin.py index b462a394..bb84a987 100644 --- a/pgweb/util/admin.py +++ b/pgweb/util/admin.py @@ -36,6 +36,25 @@ class PgwebAdmin(admin.ModelAdmin): return super(PgwebAdmin, self).change_view(request, object_id, extra_context) + # Remove the builtin delete_selected action, so it doesn't + # conflict with the custom one. + def get_actions(self, request): + actions = super(PgwebAdmin, self).get_actions(request) + del actions['delete_selected'] + return actions + + # Define a custom delete_selected action. This is required because the + # default one uses the delete functionality in QuerySet, which bypasses + # the delete() operation on the model, and thus won't send out our + # notifications. Manually calling delete() on each one will be slightly + # slower, but will send proper notifications - and it's not like this + # is something that happens often enough that we care about performance. + def custom_delete_selected(self, request, queryset): + for x in queryset: + x.delete() + custom_delete_selected.short_description = "Delete selected items" + actions=['custom_delete_selected'] + def save_model(self, request, obj, form, change): if change and self.model.send_notification: # We only do processing if something changed, not when adding -- 2.39.5