=====================
The Django admin site
=====================

One of the most powerful parts of Django is the automatic admin interface. It
reads metadata in your model to provide a powerful and production-ready
interface that content producers can immediately use to start adding content to
the site. In this document, we discuss how to activate, use and customize
Django's admin interface.

.. admonition:: Note

    The admin site has been refactored significantly since Django 0.96. This
    document describes the newest version of the admin site, which allows for
    much richer customization. If you follow the development of Django itself,
    you may have heard this described as "newforms-admin."

Overview
========

There are four steps in activating the Django admin site:

    1. Determine which of your application's models should be editable in the
       admin interface.

    2. For each of those models, optionally create a ``ModelAdmin`` class that
       encapsulates the customized admin functionality and options for that
       particular model.

    3. Instantiate an ``AdminSite`` and tell it about each of your models and
       ``ModelAdmin`` classes.

    4. Hook the ``AdminSite`` instance into your URLconf.

``ModelAdmin`` objects
======================

``AdminSite`` objects
=====================

Hooking ``AdminSite`` instances into your URLconf
=================================================

The last step in setting up the Django admin is to hook your ``AdminSite``
instance into your URLconf. Do this by pointing a given URL at the
``AdminSite.root`` method.

In this example, we register the default ``AdminSite`` instance
``django.contrib.admin.site`` at the URL ``/admin/`` ::

    # urls.py
    from django.conf.urls.defaults import *
    from django.contrib import admin

    urlpatterns = patterns('',
        ('^admin/(.*)', admin.site.root),
    )

In this example, we register the ``AdminSite`` instance
``myproject.admin.admin_site`` at the URL ``/myadmin/`` ::

    # urls.py
    from django.conf.urls.defaults import *
    from myproject.admin import admin_site

    urlpatterns = patterns('',
        ('^myadmin/(.*)', admin_site.root),
    )

Note that the regular expression in the URLpattern *must* group everything in
the URL that comes after the URL root -- hence the ``(.*)`` in these examples.

Multiple admin sites in the same URLconf
----------------------------------------

It's easy to create multiple instances of the admin site on the same
Django-powered Web site. Just create multiple instances of ``AdminSite`` and
root each one at a different URL.

In this example, the URLs ``/basic-admin/`` and ``/advanced-admin/`` feature
separate versions of the admin site -- using the ``AdminSite`` instances
``myproject.admin.basic_site`` and ``myproject.admin.advanced_site``,
respectively.

    # urls.py
    from django.conf.urls.defaults import *
    from myproject.admin import basic_site, advanced_site

    urlpatterns = patterns('',
        ('^basic-admin/(.*)', basic_site.root),
        ('^advanced-admin/(.*)', advanced_site.root),
    )
