From de26baf75ac1c4dbe8067849307936d998f2a6a9 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 8 Jul 2021 13:49:24 +0200 Subject: [PATCH] Refactor TransactionProcessAdmin.delete_selected override Override `delete_queryset` instead of overriding `delete_selected` action. Fixes admin.E130 error. Related ticket https://github.com/django/django/pull/10603 --- orchestra/contrib/payments/actions.py | 10 ---------- orchestra/contrib/payments/admin.py | 9 ++++++++- orchestra/contrib/payments/helpers.py | 1 - 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/orchestra/contrib/payments/actions.py b/orchestra/contrib/payments/actions.py index e6b4b348..d2f5a433 100644 --- a/orchestra/contrib/payments/actions.py +++ b/orchestra/contrib/payments/actions.py @@ -175,16 +175,6 @@ commit.url_name = 'commit' commit.short_description = _("Commit") -def delete_selected(modeladmin, request, queryset): - """ Has to have same name as admin.actions.delete_selected """ - related_transactions = helpers.pre_delete_processes(modeladmin, request, queryset) - response = actions.delete_selected(modeladmin, request, queryset) - if response is None: - helpers.post_delete_processes(modeladmin, request, related_transactions) - return response -delete_selected.short_description = actions.delete_selected.short_description - - def report(modeladmin, request, queryset): if queryset.model == Transaction: transactions = queryset diff --git a/orchestra/contrib/payments/admin.py b/orchestra/contrib/payments/admin.py index 45b67a48..016543ac 100644 --- a/orchestra/contrib/payments/admin.py +++ b/orchestra/contrib/payments/admin.py @@ -179,7 +179,7 @@ class TransactionProcessAdmin(ChangeViewActionsMixin, admin.ModelAdmin): change_view_actions = ( actions.mark_process_as_executed, actions.abort, actions.commit, actions.report ) - actions = change_view_actions + (actions.delete_selected,) + actions = change_view_actions display_state = admin_colored('state', colors=PROCESS_STATE_COLORS) display_created_at = admin_date('created_at', short_description=_("Created")) @@ -233,6 +233,13 @@ class TransactionProcessAdmin(ChangeViewActionsMixin, admin.ModelAdmin): helpers.post_delete_processes(self, request, related_transactions) return response + def delete_queryset(self, request, queryset): + # override default admin action delete behaviour + related_transactions = helpers.pre_delete_processes(self, request, queryset) + super().delete_queryset(self, request, queryset) + helpers.post_delete_processes(self, request, related_transactions) + + admin.site.register(PaymentSource, PaymentSourceAdmin) admin.site.register(Transaction, TransactionAdmin) admin.site.register(TransactionProcess, TransactionProcessAdmin) diff --git a/orchestra/contrib/payments/helpers.py b/orchestra/contrib/payments/helpers.py index 9fde2489..b6645d53 100644 --- a/orchestra/contrib/payments/helpers.py +++ b/orchestra/contrib/payments/helpers.py @@ -5,7 +5,6 @@ from .models import Transaction def pre_delete_processes(modeladmin, request, queryset): - """ Has to have same name as admin.actions.delete_selected """ if not queryset: messages.warning(request, _("No transaction process selected."))