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:
parent
50f916fa4d
commit
de26baf75a
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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."))
|
||||
|
|
Loading…
Reference in New Issue