summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorUnai Zalakain <unai@gisa-elkartea.org>2013-10-24 17:28:09 +0200
committerSimon Charette <charette.s@gmail.com>2013-10-29 17:10:12 -0400
commitfd219fa24c7911adab60e1f5e4fd3d7f9d82a969 (patch)
treebebe575f54927599841c3be976eccfeeb7d84e49 /docs/ref
parent497930b7f69e2c298faa3f784c4523ea351e5e6f (diff)
Fixed #8261 -- ModelAdmin hook for customising the "show on site" button
``ModelAdmin.view_on_site`` defines wether to show a link to the object on the admin detail page. If ``True``, cleverness (i.e. ``Model.get_absolute_url``) is used to get the url. If it's a callable, the callable is called with the object as the only parameter. If ``False``, not link is displayed. With the aim of maitaining backwards compatibility, ``True`` is the default.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/contrib/admin/index.txt31
1 files changed, 31 insertions, 0 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 8873375174..1301437df2 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -1091,6 +1091,37 @@ subclass::
:meth:`ModelAdmin.get_search_results` to provide additional or alternate
search behavior.
+.. attribute:: ModelAdmin.view_on_site
+
+ .. versionadded:: 1.7
+
+ 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 :meth:`~django.db.models.Model.get_absolute_url`
+ method will be used to generate the url.
+
+ If your model has a :meth:`~django.db.models.Model.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``::
+
+ 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::
+
+ from django.contrib import admin
+ from django.core.urlresolvers import reverse
+
+ class PersonAdmin(admin.ModelAdmin):
+ def view_on_site(self, obj):
+ return 'http://example.com' + reverse('person-detail',
+ kwargs={'slug': obj.slug})
+
Custom template options
~~~~~~~~~~~~~~~~~~~~~~~