python - Making Django Readonly ForeignKey Field in Admin Render as a Link -


I have a model that came in the admin of the admin, which reads the model admin's readonly_fields as "user" Adding Django's user model that uses FORGINKINI that uses the field to show. By default, readonly_fields causes this field to be presented as a simple text of a user's email (eg someuser@domain.com ). How do I change that user to present as a link to the affiliate admin page? (E.g. & lt; a href = "/ admin / auth / user / 123 /" & gt; someuser@domain.com< / a & gt; ) < P>

For example django.contrib import admin django.utils.safestring import mark_safe from django.core import urlresolvers class from MyModelAdmin (Admin.ModelAdmin): readonly_fields = ['user_link'] def user_link (auto, obj) ): Change_url = urlresolvers.reverse ('admin: auth_user_change', args = (obj.user.id,)) return mark_safe ('& lt; a href = "% s" & gt;% s & lt; / a & Gt; '% (change_url, obj.user.email)) user_link.short_description =' user '

Comments