diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 326bca4d18b..ca7609cf803 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -11,13 +11,6 @@ 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 ======== @@ -26,8 +19,8 @@ There are six steps in activating the Django admin site: 1. Add ``'django.contrib.admin'`` to your :setting:`INSTALLED_APPS` setting. - 2. Admin has two dependencies - ``django.contrib.auth`` and - ``django.contrib.contenttypes``. If these applications are not + 2. Admin has two dependencies - :mod:`django.contrib.auth` and + :mod:`django.contrib.contenttypes`. If these applications are not in your :setting:`INSTALLED_APPS` list, add them. 3. Determine which of your application's models should be editable in the @@ -87,7 +80,7 @@ Other topics admin.site.register(Author) -``ModelAdmin`` Options +``ModelAdmin`` options ---------------------- The ``ModelAdmin`` is very flexible. It has several options for dealing with @@ -97,6 +90,26 @@ subclass:: class AuthorAdmin(admin.ModelAdmin): date_hierarchy = 'pub_date' +.. attribute:: ModelAdmin.actions + + A list of actions to make available on the change list page. See + :doc:`/ref/contrib/admin/actions` for details. + +.. attribute:: ModelAdmin.actions_on_top +.. attribute:: ModelAdmin.actions_on_bottom + + Controls where on the page the actions bar appears. By default, the admin + changelist displays actions at the top of the page (``actions_on_top = True; + actions_on_bottom = False``). + +.. attribute:: ModelAdmin.actions_selection_counter + + .. versionadded:: 1.2 + + Controls whether a selection counter is display next to the action dropdown. + By default, the admin changelist will display it + (``actions_selection_counter = True``). + .. attribute:: ModelAdmin.date_hierarchy Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField`` @@ -109,18 +122,59 @@ subclass:: .. versionadded:: 1.3 - This will intelligently populate itself based on available data, - e.g. if all the dates are in one month, it'll show the day-level - drill-down only. + This will intelligently populate itself based on available data, + e.g. if all the dates are in one month, it'll show the day-level + drill-down only. -.. attribute:: ModelAdmin.form +.. attribute:: ModelAdmin.exclude - By default a ``ModelForm`` is dynamically created for your model. It is - used to create the form presented on both the add/change pages. You can - easily provide your own ``ModelForm`` to override any default form behavior - on the add/change pages. + This attribute, if given, should be a list of field names to exclude from + the form. - For an example see the section `Adding custom validation to the admin`_. + For example, let's consider the following model:: + + class Author(models.Model): + name = models.CharField(max_length=100) + title = models.CharField(max_length=3) + birth_date = models.DateField(blank=True, null=True) + + If you want a form for the ``Author`` model that includes only the ``name`` + and ``title`` fields, you would specify ``fields`` or ``exclude`` like + this:: + + class AuthorAdmin(admin.ModelAdmin): + fields = ('name', 'title') + + class AuthorAdmin(admin.ModelAdmin): + exclude = ('birth_date',) + + Since the Author model only has three fields, ``name``, ``title``, and + ``birth_date``, the forms resulting from the above declarations will + contain exactly the same fields. + +.. attribute:: ModelAdmin.fields + + Use this option as an alternative to ``fieldsets`` if the layout does not + matter and if you want to only show a subset of the available fields in the + form. For example, you could define a simpler version of the admin form for + the ``django.contrib.flatpages.FlatPage`` model as follows:: + + class FlatPageAdmin(admin.ModelAdmin): + fields = ('url', 'title', 'content') + + In the above example, only the fields 'url', 'title' and 'content' will be + displayed, sequentially, in the form. + + .. versionadded:: 1.2 + + ``fields`` can contain values defined in :attr:`ModelAdmin.readonly_fields` + to be displayed as read-only. + + .. admonition:: Note + + This ``fields`` option should not be confused with the ``fields`` + dictionary key that is within the ``fieldsets`` option, as described in + the previous section. .. attribute:: ModelAdmin.fieldsets @@ -207,56 +261,6 @@ subclass:: ``django.utils.html.escape()`` to escape any HTML special characters. -.. attribute:: ModelAdmin.fields - - Use this option as an alternative to ``fieldsets`` if the layout does not - matter and if you want to only show a subset of the available fields in the - form. For example, you could define a simpler version of the admin form for - the ``django.contrib.flatpages.FlatPage`` model as follows:: - - class FlatPageAdmin(admin.ModelAdmin): - fields = ('url', 'title', 'content') - - In the above example, only the fields 'url', 'title' and 'content' will be - displayed, sequentially, in the form. - - .. versionadded:: 1.2 - - ``fields`` can contain values defined in :attr:`ModelAdmin.readonly_fields` - to be displayed as read-only. - - .. admonition:: Note - - This ``fields`` option should not be confused with the ``fields`` - dictionary key that is within the ``fieldsets`` option, as described in - the previous section. - -.. attribute:: ModelAdmin.exclude - - This attribute, if given, should be a list of field names to exclude from - the form. - - For example, let's consider the following model:: - - class Author(models.Model): - name = models.CharField(max_length=100) - title = models.CharField(max_length=3) - birth_date = models.DateField(blank=True, null=True) - - If you want a form for the ``Author`` model that includes only the ``name`` - and ``title`` fields, you would specify ``fields`` or ``exclude`` like - this:: - - class AuthorAdmin(admin.ModelAdmin): - fields = ('name', 'title') - - class AuthorAdmin(admin.ModelAdmin): - exclude = ('birth_date',) - - Since the Author model only has three fields, ``name``, ``title``, and - ``birth_date``, the forms resulting from the above declarations will - contain exactly the same fields. - .. attribute:: ModelAdmin.filter_horizontal Use a nifty unobtrusive JavaScript "filter" interface instead of the @@ -269,6 +273,61 @@ subclass:: Same as ``filter_horizontal``, but is a vertical display of the filter interface. +.. attribute:: ModelAdmin.form + + By default a ``ModelForm`` is dynamically created for your model. It is + used to create the form presented on both the add/change pages. You can + easily provide your own ``ModelForm`` to override any default form behavior + on the add/change pages. + + For an example see the section `Adding custom validation to the admin`_. + +.. attribute:: ModelAdmin.formfield_overrides + + This provides a quick-and-dirty way to override some of the + :class:`~django.forms.Field` options for use in the admin. + ``formfield_overrides`` is a dictionary mapping a field class to a dict of + arguments to pass to the field at construction time. + + Since that's a bit abstract, let's look at a concrete example. The most + common use of ``formfield_overrides`` is to add a custom widget for a + certain type of field. So, imagine we've written a ``RichTextEditorWidget`` + that we'd like to use for large text fields instead of the default + ``