Display model url in admin

I have a couple of models. None of them have other types of browsing except their administrator entries. For this reason, it’s a little painful to manually work out the URLs for model instances.

I would like to show a link to the listing and details of the administrators who lead me directly to the public presentation. I can make nonsense that works, create a URL, but I don’t know how to show it in the admin.

Any ideas?

+7
django django-admin
source share
1 answer

If the model has the get_absolute_url() method, there should automatically be a "Browse on site" button in the upper right corner of the admin information screen.

To view the list, you can easily add the method to the list of displayed fields:

 class MyAdmin(admin.ModelAdmin): list_display=('name', 'anotherfield', 'show_url') def show_url(self, instance): return '<a href="%s">View on site</a>' % (instance.get_absolute_url()) show_url.allow_tags = True 
+12
source share

All Articles