Repository: django/django
Issue category: Bug Report

Issue:
"view on site" URL doesn't accept non-integer ContentType pks
Description
	 
Most admin URL paths use the path converter to allow any type of ID, however, the "view on site" uses the int converter for content_type_id.
This doesn't work on MongoDB which uses ObjectIdAutoField (bson.ObjectId) for all models since AutoField isn't supported.


Hints:

Patch:
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index dc67262afc50..3399bd87b85a 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -282,7 +282,7 @@ def wrapper(*args, **kwargs):
             path("autocomplete/", wrap(self.autocomplete_view), name="autocomplete"),
             path("jsi18n/", wrap(self.i18n_javascript, cacheable=True), name="jsi18n"),
             path(
-                "r/<int:content_type_id>/<path:object_id>/",
+                "r/<path:content_type_id>/<path:object_id>/",
                 wrap(contenttype_views.shortcut),
                 name="view_on_site",
             ),


Test patch:
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index c5d8b8f4f668..3f106f681418 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -8664,6 +8664,19 @@ def test_custom_admin_site(self):
             ),
         )
 
+    def test_view_on_site_url_non_integer_ids(self):
+        """The view_on_site URL accepts non-integer ids."""
+        self.assertEqual(
+            reverse(
+                "admin:view_on_site",
+                kwargs={
+                    "content_type_id": "37156b6a-8a82",
+                    "object_id": "37156b6a-8a83",
+                },
+            ),
+            "/test_admin/admin/r/37156b6a-8a82/37156b6a-8a83/",
+        )
+
 
 @override_settings(ROOT_URLCONF="admin_views.urls")
 class InlineAdminViewOnSiteTest(TestCase):