From dc35e54f4ea0a9bce3b9bf712bde9ec730e45830 Mon Sep 17 00:00:00 2001 From: Robert Habermann Date: Fri, 6 Nov 2020 23:01:19 +0100 Subject: [PATCH] Use ModelAdmin.opts for correct reverse in admin Make sure to use ModelAdmin.opts in admin.py in order to get the correct app_label and model_name. This is important when a subclass (e.g. of Newsletter) is used --- newsletter/admin.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/newsletter/admin.py b/newsletter/admin.py index 20157f36..e1b7f026 100644 --- a/newsletter/admin.py +++ b/newsletter/admin.py @@ -168,8 +168,9 @@ def submit(self, request, object_id): if submission.sent or submission.prepared: messages.info(request, _("Submission already sent.")) change_url = reverse( - 'admin:newsletter_submission_change', args=[object_id] + 'admin:%s_%s_change' % (self.opts.app_label, self.opts.model_name), args=[object_id] ) + return HttpResponseRedirect(change_url) submission.prepared = True @@ -177,7 +178,7 @@ def submit(self, request, object_id): messages.info(request, _("Your submission is being sent.")) - changelist_url = reverse('admin:newsletter_submission_changelist') + changelist_url = reverse('admin:%s_%s_changelist' % (self.opts.app_label, self.opts.model_name)) return HttpResponseRedirect(changelist_url) """ URLs """ @@ -439,7 +440,7 @@ def subscribers_import(self, request): form.cleaned_data['newsletter'].pk confirm_url = reverse( - 'admin:newsletter_subscription_import_confirm' + 'admin:%s_%s_import_confirm' % (self.opts.app_label, self.opts.model_name) ) return HttpResponseRedirect(confirm_url) else: @@ -453,9 +454,8 @@ def subscribers_import(self, request): def subscribers_import_confirm(self, request): # If no addresses are in the session, start all over. - if 'addresses' not in request.session: - import_url = reverse('admin:newsletter_subscription_import') + import_url = reverse('admin:%s_%s_import' % (self.opts.app_label, self.opts.model_name)) return HttpResponseRedirect(import_url) addresses = request.session['addresses'] @@ -488,7 +488,7 @@ def subscribers_import_confirm(self, request): ) changelist_url = reverse( - 'admin:newsletter_subscription_changelist' + 'admin:%s_%s_changelist' % (self.opts.app_label, self.opts.model_name) ) return HttpResponseRedirect(changelist_url) else: