ModelAdmin.view_on_site
Set view_on_site
to control whether or not to display the “View on site” link. This link should bring you to a URL where you can display the saved object.
This value can be either a boolean flag or a callable. If True
(the default), the object’s get_absolute_url()
method will be used to generate the url.
If your model has a get_absolute_url()
method but you don’t want the “View on site” button to appear, you only need to set view_on_site
to False
:
1 2 3 4 | from django.contrib import admin class PersonAdmin(admin.ModelAdmin): view_on_site = False |
In case it is a callable, it accepts the model instance as a parameter. For example:
1 2 3 4 5 6 7 | from django.contrib import admin from django.urls import reverse class PersonAdmin(admin.ModelAdmin): def view_on_site( self , obj): url = reverse( 'person-detail' , kwargs = { 'slug' : obj.slug}) |
Please login to continue.