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
This commit is contained in:
Santiago L 2021-07-08 13:49:24 +02:00
parent 50f916fa4d
commit de26baf75a
3 changed files with 8 additions and 12 deletions

View File

@ -175,16 +175,6 @@ commit.url_name = 'commit'
commit.short_description = _("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): def report(modeladmin, request, queryset):
if queryset.model == Transaction: if queryset.model == Transaction:
transactions = queryset transactions = queryset

View File

@ -179,7 +179,7 @@ class TransactionProcessAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
change_view_actions = ( change_view_actions = (
actions.mark_process_as_executed, actions.abort, actions.commit, actions.report 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_state = admin_colored('state', colors=PROCESS_STATE_COLORS)
display_created_at = admin_date('created_at', short_description=_("Created")) 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) helpers.post_delete_processes(self, request, related_transactions)
return response 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(PaymentSource, PaymentSourceAdmin)
admin.site.register(Transaction, TransactionAdmin) admin.site.register(Transaction, TransactionAdmin)
admin.site.register(TransactionProcess, TransactionProcessAdmin) admin.site.register(TransactionProcess, TransactionProcessAdmin)

View File

@ -5,7 +5,6 @@ from .models import Transaction
def pre_delete_processes(modeladmin, request, queryset): def pre_delete_processes(modeladmin, request, queryset):
""" Has to have same name as admin.actions.delete_selected """
if not queryset: if not queryset:
messages.warning(request, messages.warning(request,
_("No transaction process selected.")) _("No transaction process selected."))