mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #8500 -- Allowed overriding the default admin site instance.
This commit is contained in:
parent
d0a42a14c0
commit
da3df5b878
9 changed files with 108 additions and 2 deletions
|
@ -157,6 +157,15 @@ application and imports it.
|
|||
This class works like :class:`~django.contrib.admin.apps.AdminConfig`,
|
||||
except it doesn't call :func:`~django.contrib.admin.autodiscover()`.
|
||||
|
||||
.. attribute:: default_site
|
||||
|
||||
.. versionadded:: 2.1
|
||||
|
||||
A dotted import path to the default admin site's class or to a callable
|
||||
that returns a site instance. Defaults to
|
||||
``'django.contrib.admin.sites.AdminSite'``. See
|
||||
:ref:`overriding-default-admin-site` for usage.
|
||||
|
||||
.. function:: autodiscover
|
||||
|
||||
This function attempts to import an ``admin`` module in each installed
|
||||
|
@ -2627,6 +2636,9 @@ 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 want to customize the default admin site, you can :ref:`override it
|
||||
<overriding-default-admin-site>`.
|
||||
|
||||
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
|
||||
|
@ -2819,6 +2831,43 @@ own ``AdminSite`` instance since you will likely be importing all the per-app
|
|||
put ``'django.contrib.admin.apps.SimpleAdminConfig'`` instead of
|
||||
``'django.contrib.admin'`` in your :setting:`INSTALLED_APPS` setting.
|
||||
|
||||
.. _overriding-default-admin-site:
|
||||
|
||||
Overriding the default admin site
|
||||
---------------------------------
|
||||
|
||||
.. versionadded:: 2.1
|
||||
|
||||
You can override the default ``django.contrib.admin.site`` by setting the
|
||||
:attr:`~.SimpleAdminConfig.default_site` attribute of a custom ``AppConfig``
|
||||
to the dotted import path of either a ``AdminSite`` subclass or a callable that
|
||||
returns a site instance.
|
||||
|
||||
.. snippet::
|
||||
:filename: myproject/admin.py
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
class MyAdminSite(admin.AdminSite):
|
||||
...
|
||||
|
||||
.. snippet::
|
||||
:filename: myproject/apps.py
|
||||
|
||||
from django.contrib.admin.apps import AdminConfig
|
||||
|
||||
class MyAdminConfig(AdminConfig):
|
||||
default_site = 'myproject.admin.MyAdminSite'
|
||||
|
||||
.. snippet::
|
||||
:filename: myproject/settings.py
|
||||
|
||||
INSTALLED_APPS = [
|
||||
...
|
||||
'myproject.apps.MyAdminConfig', # replaces 'django.contrib.admin'
|
||||
...
|
||||
]
|
||||
|
||||
.. _multiple-admin-sites:
|
||||
|
||||
Multiple admin sites in the same URLconf
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue