| 15 | | much richer customization. If you've kept up with Django development, you |
|---|
| 16 | | may have heard this described as "newforms-admin." |
|---|
| | 15 | much richer customization. If you follow the development of Django itself, |
|---|
| | 16 | you may have heard this described as "newforms-admin." |
|---|
| | 17 | |
|---|
| | 18 | Overview |
|---|
| | 19 | ======== |
|---|
| | 20 | |
|---|
| | 21 | There are four steps in activating the Django admin site: |
|---|
| | 22 | |
|---|
| | 23 | 1. Determine which of your application's models should be editable in the |
|---|
| | 24 | admin interface. |
|---|
| | 25 | |
|---|
| | 26 | 2. For each of those models, optionally create a ``ModelAdmin`` class that |
|---|
| | 27 | encapsulates the customized admin functionality and options for that |
|---|
| | 28 | particular model. |
|---|
| | 29 | |
|---|
| | 30 | 3. Instantiate an ``AdminSite`` and tell it about each of your models and |
|---|
| | 31 | ``ModelAdmin`` classes. |
|---|
| | 32 | |
|---|
| | 33 | 4. Hook the ``AdminSite`` instance into your URLconf. |
|---|
| | 34 | |
|---|
| | 35 | ``ModelAdmin`` objects |
|---|
| | 36 | ====================== |
|---|
| | 37 | |
|---|
| | 38 | ``AdminSite`` objects |
|---|
| | 39 | ===================== |
|---|
| | 40 | |
|---|
| | 41 | Hooking ``AdminSite`` instances into your URLconf |
|---|
| | 42 | ================================================= |
|---|
| | 43 | |
|---|
| | 44 | The last step in setting up the Django admin is to hook your ``AdminSite`` |
|---|
| | 45 | instance into your URLconf. Do this by pointing a given URL at the |
|---|
| | 46 | ``AdminSite.root`` method. |
|---|
| | 47 | |
|---|
| | 48 | In this example, we register the ``AdminSite`` instance |
|---|
| | 49 | ``myproject.admin.admin_site`` at the URL ``/admin/`` :: |
|---|
| | 50 | |
|---|
| | 51 | from django.conf.urls.defaults import * |
|---|
| | 52 | from myproject.admin import admin_site |
|---|
| | 53 | |
|---|
| | 54 | urlpatterns = patterns('', |
|---|
| | 55 | ('^admin/(.*)', admin_site.root), |
|---|
| | 56 | ) |
|---|
| | 57 | |
|---|
| | 58 | In this example, we register the default ``AdminSite`` instance |
|---|
| | 59 | ``django.contrib.admin.site`` at the URL ``/myadmin/`` :: |
|---|
| | 60 | |
|---|
| | 61 | from django.conf.urls.defaults import * |
|---|
| | 62 | from django.contrib import admin |
|---|
| | 63 | |
|---|
| | 64 | urlpatterns = patterns('', |
|---|
| | 65 | ('^myadmin/(.*)', admin.site.root), |
|---|
| | 66 | ) |
|---|
| | 67 | |
|---|
| | 68 | Note that the regular expression in the URLpattern *must* group everything in |
|---|
| | 69 | the URL that comes after the URL root -- hence the ``(.*)`` in these examples. |
|---|