summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-10-30 13:57:22 +0200
committerTim Graham <timograham@gmail.com>2014-10-30 08:46:14 -0400
commit4a9b4a23bdb51c9fce06facaf78c9ba0a54f1266 (patch)
tree6be2d34b7d0b8d448d6b821f9e931703d0c18105 /docs/ref
parent68d3db8a7b3dfe2690df3e7f750a5010086d6aa6 (diff)
Fixed #23575 -- Added a code example for custom AdminSite.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/contrib/admin/index.txt43
1 files changed, 31 insertions, 12 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 51d7c34022..da15ec2451 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -2431,18 +2431,13 @@ creating your own ``AdminSite`` instance (see below), and changing the
this class is created as ``django.contrib.admin.site`` and you can
register your models and ``ModelAdmin`` instances with it.
- If you'd like to set up your own administrative site with custom
- behavior, however, you're free to subclass ``AdminSite`` and override
- or add anything you like. Then, simply create an instance of your
- ``AdminSite`` subclass (the same way you'd instantiate any other
- Python class), and register your models and ``ModelAdmin`` subclasses
- with it instead of using the default.
-
When constructing an instance of an ``AdminSite``, you can provide
a unique instance name using the ``name`` argument to the constructor. This
instance name is used to identify the instance, especially when
:ref:`reversing admin URLs <admin-reverse-urls>`. If no instance name is
provided, a default instance name of ``admin`` will be used.
+ See :ref:`customizing-adminsite` for an example of customizing the
+ :class:`AdminSite` class.
``AdminSite`` attributes
------------------------
@@ -2528,12 +2523,36 @@ In this example, we register the default ``AdminSite`` instance
url(r'^admin/', include(admin.site.urls)),
]
-In this example, we register the ``AdminSite`` instance
-``myproject.admin.admin_site`` at the URL ``/myadmin/`` ::
+.. _customizing-adminsite:
- # urls.py
- from django.conf.urls import include, url
- from myproject.admin import admin_site
+Customizing the :class:`AdminSite` class
+----------------------------------------
+
+If you'd like to set up your own admin site with custom behavior, you're free
+to subclass ``AdminSite`` and override or add anything you like. Then, simply
+create an instance of your ``AdminSite`` subclass (the same way you'd
+instantiate any other Python class) and register your models and
+``ModelAdmin`` subclasses with it instead of with the default site. Finally,
+update :file:`myproject/urls.py` to reference your :class:`AdminSite` subclass.
+
+.. snippet::
+ :filename: myapp/admin.py
+
+ from django.contrib.admin import AdminSite
+
+ from .models import MyModel
+
+ class MyAdminSite(AdminSite):
+ site_header = 'Monty Python administration'
+
+ admin_site = MyAdminSite(name='myadmin')
+ admin_site.register(MyModel)
+
+
+.. snippet::
+ :filename: myproject/urls.py
+
+ from myapp.admin import admin_site
urlpatterns = [
url(r'^myadmin/', include(admin_site.urls)),