diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index dd154f72eea..dae626b5500 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -209,7 +209,11 @@ class AdminReadonlyField: remote_field.model._meta.model_name, ) try: - url = reverse(url_name, args=[quote(remote_obj.pk)]) + url = reverse( + url_name, + args=[quote(remote_obj.pk)], + current_app=self.model_admin.admin_site.name, + ) return format_html('{}', url, remote_obj) except NoReverseMatch: return str(remote_obj) diff --git a/docs/releases/3.2.8.txt b/docs/releases/3.2.8.txt index add283a6728..8494b292cbd 100644 --- a/docs/releases/3.2.8.txt +++ b/docs/releases/3.2.8.txt @@ -9,4 +9,5 @@ Django 3.2.8 fixes several bugs in 3.2.7. Bugfixes ======== -* ... +* Fixed a bug in Django 3.2 that caused incorrect links on read-only fields in + admin (:ticket:`33077`). diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index e2ecc9ed53b..dac4517b2bb 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -1142,6 +1142,8 @@ site2.register( raw_id_fields=['parent'], ) site2.register(Person, save_as_continue=False) +site2.register(ReadOnlyRelatedField, ReadOnlyRelatedFieldAdmin) +site2.register(Language) site7 = admin.AdminSite(name="admin7") site7.register(Article, ArticleAdmin2) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 9f9e924b620..57da633d736 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -5093,7 +5093,7 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase): response = self.client.get(reverse('admin:admin_views_choice_change', args=(choice.pk,))) self.assertContains(response, '