Fixed #33592 -- Fixed "View on Site" links in custom admin site.

This commit is contained in:
Stefan Wehrmeyer 2022-03-18 13:37:16 +01:00 committed by Mariusz Felisiak
parent b07ee98b27
commit 561761c660
2 changed files with 16 additions and 0 deletions

View File

@ -347,6 +347,7 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
"content_type_id": get_content_type_for_model(obj).pk, "content_type_id": get_content_type_for_model(obj).pk,
"object_id": obj.pk, "object_id": obj.pk,
}, },
current_app=self.admin_site.name,
) )
def get_empty_value_display(self): def get_empty_value_display(self):

View File

@ -7930,6 +7930,21 @@ class AdminViewOnSiteTests(TestCase):
model_admin = ModelAdmin(Worker, None) model_admin = ModelAdmin(Worker, None)
self.assertIsNone(model_admin.get_view_on_site_url(Worker())) self.assertIsNone(model_admin.get_view_on_site_url(Worker()))
def test_custom_admin_site(self):
model_admin = ModelAdmin(City, customadmin.site)
content_type_pk = ContentType.objects.get_for_model(City).pk
redirect_url = model_admin.get_view_on_site_url(self.c1)
self.assertEqual(
redirect_url,
reverse(
f"{customadmin.site.name}:view_on_site",
kwargs={
"content_type_id": content_type_pk,
"object_id": self.c1.pk,
},
),
)
@override_settings(ROOT_URLCONF="admin_views.urls") @override_settings(ROOT_URLCONF="admin_views.urls")
class InlineAdminViewOnSiteTest(TestCase): class InlineAdminViewOnSiteTest(TestCase):