﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34767	AdminReadonlyField may not show links to related models when the related model has been downcasted	matthias-margin	nobody	"`get_admin_url` uses the `remote_field.model` to generate the view name to use to link to the model. However, the model can be downcasted into a different class (eg by using TypedModels). If this downcasted class is the one that has an admin registered and the base class does not, then the link is not rendered. 

Fortunately, the `get_admin_url` method already gets the instance of the model (`remote_obj`), which can be used instead to generate the view name.


{{{
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index 90ca7affc8..25c1f89a71 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -243,10 +243,10 @@ class AdminReadonlyField:
             self.form.label_suffix,
         )
 
-    def get_admin_url(self, remote_field, remote_obj):
+    def get_admin_url(self, remote_obj):
         url_name = ""admin:%s_%s_change"" % (
-            remote_field.model._meta.app_label,
-            remote_field.model._meta.model_name,
+            remote_obj._meta.app_label,
+            remote_obj._meta.model_name,
         )
         try:
             url = reverse(
@@ -292,7 +292,7 @@ class AdminReadonlyField:
                     isinstance(f.remote_field, (ForeignObjectRel, OneToOneField))
                     and value is not None
                 ):
-                    result_repr = self.get_admin_url(f.remote_field, value)
+                    result_repr = self.get_admin_url(value)
                 else:
                     result_repr = display_for_field(value, f, self.empty_value_display)
                 result_repr = linebreaksbr(result_repr)
}}}

this change should be a no-op change most everyone.

I tried to add tests but could not find where this was being tested. Happy to put out a pull request in github is someone can point me to the right place to update tests."	Cleanup/optimization	closed	contrib.admin	4.2	Normal	needsinfo			Unreviewed	0	0	0	0	0	1
