Ticket #10726: admin-url-docs.diff

File admin-url-docs.diff, 6.5 KB (added by Alex Gaynor, 15 years ago)
  • docs/ref/contrib/admin/index.txt

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    index 4638295..3b04d54 100644
    a b Other topics  
    4646   :maxdepth: 1
    4747
    4848   actions
    49    
     49
    5050.. seealso::
    5151
    5252    For information about serving the media files (images, JavaScript, and CSS)
    parent model. These are called inlines. Suppose you have these two models::  
    846846        author = models.ForeignKey(Author)
    847847        title = models.CharField(max_length=100)
    848848
    849 You can edit the books authored by an author on the author page. You add 
     849You can edit the books authored by an author on the author page. You add
    850850inlines to a model by specifying them in a ``ModelAdmin.inlines``::
    851851
    852852    class BookInline(admin.TabularInline):
    If you wish to change the index or login templates, you are better off creating  
    11601160your own ``AdminSite`` instance (see below), and changing the ``index_template``
    11611161or ``login_template`` properties.
    11621162
    1163 Linking to admin views
    1164 ======================
    1165 
    1166 .. versionadded:: 1.1
    1167 
    1168 All the admin views use :ref:`named URL patterns <naming-url-patterns>` so it's
    1169 easy to link to admin views with ``urlresolvers.reverse`` or the :ttag:`url`
    1170 template tag.
    1171 
    1172 Each model gets its own set of views and its own name using the model's app name
    1173 and model name. For example, the "add" view for a ``Choice`` model in a
    1174 ``polls`` app would be named ``"admin_polls_choice_add"``.
    1175 
    1176 All the available views and their names are:
    1177 
    1178     ==============  ======================================  ===================
    1179     View            View name                               Parameters
    1180     ==============  ======================================  ===================
    1181     Change list     ``"admin_<app>_<model>_changelist"``    None
    1182     Add object      ``"admin_<app>_<model>_add"``           None
    1183     Change object   ``"admin_<app>_<model>_change"``        ``object_id``
    1184     Delete object   ``"admin_<app>_<model>_delete"``        ``object_id``
    1185     Object history  ``"admin_<app>_<model>_history"``       ``object_id``
    1186     ==============  ======================================  ===================
    1187 
    1188 For example, to get the change URL for a particular ``Choice`` object::
    1189 
    1190     >>> from django.core import urlresolvers
    1191     >>> c = Choice.objects.get(...)
    1192     >>> change_url = urlresolvers.reverse('admin_polls_choice_change', (c.id,))
    1193 
    11941163``AdminSite`` objects
    11951164=====================
    11961165
    root each one at a different URL.  
    12531222
    12541223.. versionchanged:: 1.1
    12551224    The method for hooking ``AdminSite`` instances into urls has changed in
    1256     Django 1.1.
     1225    Django 1.1
    12571226
    12581227In this example, the URLs ``/basic-admin/`` and ``/advanced-admin/`` feature
    12591228separate versions of the admin site -- using the ``AdminSite`` instances
    respectively::  
    12691238        ('^advanced-admin/', include(advanced_site.urls)),
    12701239    )
    12711240
     1241``AdminSites`` take a single argument to their constructor, their name, which
     1242can be anything you like.  This argument becomes the prefix to the URL names
     1243for the pruposes of :ref:`reversing them<admin-reverse-urls>`.  This is only
     1244necesary if you are using more than one ``AdminSite``.
     1245
    12721246Adding views to admin sites
    12731247---------------------------
    12741248
    It possible to add additional views to the admin site in the same way one can  
    12781252add them to ``ModelAdmins``.  This by using the ``get_urls()`` method on an
    12791253AdminSite in the same way as `described above`__
    12801254
     1255.. note::
     1256    Any view you render that uses the admin templates, or extends the base
     1257    admin template should include in it's context a variable named
     1258    ``admin_site`` that contains the ``AdminSite`` instances name, which for
     1259    ``AdminSite`` instances exists at ``self.name`` and for ``ModelAdmin``
     1260    instances exists at ``self.admin_site.name``.
     1261
    12811262__ `get_urls(self)`_
     1263
     1264.. _admin-reverse-urls:
     1265
     1266Reversing Admin URLs
     1267====================
     1268
     1269.. versionadded :: 1.1
     1270    Before Django 1.1 it wasn't possible to reverse admin URLs.  In addition
     1271    for this to work you need to be using the new Django 1.1 ``include()``
     1272    syntax for setting up admin URLs.
     1273
     1274The following are the url names, and parameters for ``AdminSite`` urls, all
     1275url names are prefixed with the ``AdminSite`` instace's name, followed by an
     1276underscore, so if an ``AdminSite`` was named ``"user_admin"`` it's urls names
     1277would be prefixed with ``"user_admin_"``, the default ``AdminSite``'s name is
     1278``''`` however it's names *do not* have the trailing underscore:
     1279
     1280    ======================  =============================== =============
     1281    Page                    URL name                        Parameters
     1282    ======================  =============================== =============
     1283    Index                   ``admin_index``
     1284    Logout                  ``admin_logout``
     1285    Password change         ``admin_password_change``
     1286    Password change done    ``admin_password_change_done``
     1287    i18n javascript         ``admin_jsi18n``
     1288    Application index page  ``admin_app_list``              ``app_label``
     1289    ======================  =============================== =============
     1290
     1291The remaining urls are for ``ModelAdmin`` instances, these too are all prefixed
     1292with the ``AdminSite``'s name(with the same caviets as the ``Adminsite``, and
     1293``app_label`` and ``model_name`` are the lowercase versions of the
     1294application's name and the model's name:
     1295
     1296    ======================  =====================================================   =============
     1297    Page                    URL name                                                Parameters
     1298    ======================  =====================================================   =============
     1299    Changelist              ``admin_{{ app_label }}_{{ model_name }}_changelist``
     1300    Add                     ``admin_{{ app_label }}_{{ model_name }}_add``
     1301    History                 ``admin_{{ app_label }}_{{ model_name }}_history``      ``object_id``
     1302    Delete                  ``admin_{{ app_label }}_{{ model_name }}_delete``       ``object_id``
     1303    Change                  ``admin_{{ app_label }}_{{ model_name }}_change``       ``object_id``
     1304    ======================  =====================================================   =============
     1305
     1306For example, to get the change URL for a particular ``Choice`` object, in the
     1307default admin::
     1308
     1309    >>> from django.core import urlresolvers
     1310    >>> c = Choice.objects.get(...)
     1311    >>> change_url = urlresolvers.reverse('admin_polls_choice_change', (c.id,))
Back to Top