[1.8.x] Cosmetic edits and minor fixes to docs/ref/contrib/admin/index.txt

Backport of 32f0c8f796 from master
This commit is contained in:
I am Clinton 2015-05-21 10:07:38 -05:00 committed by Tim Graham
parent 5a0e39b2d5
commit 6260ae7015
1 changed files with 33 additions and 29 deletions

View File

@ -255,12 +255,10 @@ subclass::
.. attribute:: ModelAdmin.fields .. attribute:: ModelAdmin.fields
If you need to achieve simple changes in the layout of fields in the forms Use the ``fields`` option to make simple layout changes in the forms on
of the "add" and "change" pages like only showing a subset of the available the "add" and "change" pages such as showing only a subset of available
fields, modifying their order or grouping them in rows you can use the fields, modifying their order, or grouping them into rows. For example, you
``fields`` option (for more complex layout needs see the could define a simpler version of the admin form for the
:attr:`~ModelAdmin.fieldsets` option described in the next section). For
example, you could define a simpler version of the admin form for the
:class:`django.contrib.flatpages.models.FlatPage` model as follows:: :class:`django.contrib.flatpages.models.FlatPage` model as follows::
class FlatPageAdmin(admin.ModelAdmin): class FlatPageAdmin(admin.ModelAdmin):
@ -271,6 +269,8 @@ subclass::
values defined in :attr:`ModelAdmin.readonly_fields` to be displayed as values defined in :attr:`ModelAdmin.readonly_fields` to be displayed as
read-only. read-only.
For more complex layout needs, see the :attr:`~ModelAdmin.fieldsets` option.
The ``fields`` option, unlike :attr:`~ModelAdmin.list_display`, may only The ``fields`` option, unlike :attr:`~ModelAdmin.list_display`, may only
contain names of fields on the model or the form specified by contain names of fields on the model or the form specified by
:attr:`~ModelAdmin.form`. It may contain callables only if they are listed :attr:`~ModelAdmin.form`. It may contain callables only if they are listed
@ -278,7 +278,7 @@ subclass::
To display multiple fields on the same line, wrap those fields in their own To display multiple fields on the same line, wrap those fields in their own
tuple. In this example, the ``url`` and ``title`` fields will display on the tuple. In this example, the ``url`` and ``title`` fields will display on the
same line and the ``content`` field will be displayed below them in its same line and the ``content`` field will be displayed below them on its
own line:: own line::
class FlatPageAdmin(admin.ModelAdmin): class FlatPageAdmin(admin.ModelAdmin):
@ -362,7 +362,7 @@ subclass::
listed in :attr:`~ModelAdmin.readonly_fields`. listed in :attr:`~ModelAdmin.readonly_fields`.
* ``classes`` * ``classes``
A list containing extra CSS classes to apply to the fieldset. A list or tuple containing extra CSS classes to apply to the fieldset.
Example:: Example::
@ -1107,7 +1107,7 @@ subclass::
search_fields = ['foreign_key__related_fieldname'] search_fields = ['foreign_key__related_fieldname']
For example, if you have a blog entry with an author, the following For example, if you have a blog entry with an author, the following
definition would enable search blog entries by the email address of the definition would enable searching blog entries by the email address of the
author:: author::
search_fields = ['user__email'] search_fields = ['user__email']
@ -1126,8 +1126,9 @@ subclass::
with an operator: with an operator:
``^`` ``^``
Matches the beginning of the field. For example, if ``search_fields`` Use the '^' operator to match starting at the beginning of the
is set to ``['^first_name', '^last_name']`` and a user searches for field. For example, if ``search_fields`` is set to
``['^first_name', '^last_name']`` and a user searches for
``john lennon``, Django will do the equivalent of this SQL ``WHERE`` ``john lennon``, Django will do the equivalent of this SQL ``WHERE``
clause:: clause::
@ -1141,10 +1142,11 @@ subclass::
index for this query, even though it's a ``LIKE`` query. index for this query, even though it's a ``LIKE`` query.
``=`` ``=``
Matches exactly, case-insensitive. For example, if Use the '=' operator for case-insensitive exact matching. For
``search_fields`` is set to ``['=first_name', '=last_name']`` and example, if ``search_fields`` is set to
a user searches for ``john lennon``, Django will do the equivalent ``['=first_name', '=last_name']`` and a user searches for
of this SQL ``WHERE`` clause:: ``john lennon``, Django will do the equivalent of this SQL
``WHERE`` clause::
WHERE (first_name ILIKE 'john' OR last_name ILIKE 'john') WHERE (first_name ILIKE 'john' OR last_name ILIKE 'john')
AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon') AND (first_name ILIKE 'lennon' OR last_name ILIKE 'lennon')
@ -1154,8 +1156,9 @@ subclass::
``first_name`` is exactly ``'john winston'`` (containing a space). ``first_name`` is exactly ``'john winston'`` (containing a space).
``@`` ``@``
Performs a full-text match. This is like the default search method but Using the '@' operator to perform a full text match. This is like the
uses an index. Currently this is only available for MySQL. default search method but uses an index. Currently this is only
available for MySQL.
If you need to customize search you can use If you need to customize search you can use
:meth:`ModelAdmin.get_search_results` to provide additional or alternate :meth:`ModelAdmin.get_search_results` to provide additional or alternate
@ -1308,8 +1311,8 @@ templates used by the :class:`ModelAdmin` views:
.. method:: ModelAdmin.get_search_results(request, queryset, search_term) .. method:: ModelAdmin.get_search_results(request, queryset, search_term)
The ``get_search_results`` method modifies the list of objects displayed in The ``get_search_results`` method modifies the list of objects displayed
to those that match the provided search term. It accepts the request, a into those that match the provided search term. It accepts the request, a
queryset that applies the current filters, and the user-provided search term. queryset that applies the current filters, and the user-provided search term.
It returns a tuple containing a queryset modified to implement the search, and It returns a tuple containing a queryset modified to implement the search, and
a boolean indicating if the results may contain duplicates. a boolean indicating if the results may contain duplicates.
@ -1617,9 +1620,9 @@ templates used by the :class:`ModelAdmin` views:
.. admonition:: Note .. admonition:: Note
Any ``choices`` attribute set on the formfield will limited to the form Any ``choices`` attribute set on the formfield will be limited to the
field only. If the corresponding field on the model has choices set, form field only. If the corresponding field on the model has choices
the choices provided to the form must be a valid subset of those set, the choices provided to the form must be a valid subset of those
choices, otherwise the form submission will fail with choices, otherwise the form submission will fail with
a :exc:`~django.core.exceptions.ValidationError` when the model itself a :exc:`~django.core.exceptions.ValidationError` when the model itself
is validated before saving. is validated before saving.
@ -2070,7 +2073,7 @@ The ``InlineModelAdmin`` class adds:
overhead of having to select all the related instances to display in the overhead of having to select all the related instances to display in the
drop-down. drop-down.
``raw_id_fields`` is a list of fields you would like to change into a ``raw_id_fields`` is a list of fields you would like to change into an
``Input`` widget for either a ``ForeignKey`` or ``ManyToManyField``:: ``Input`` widget for either a ``ForeignKey`` or ``ManyToManyField``::
class BookInline(admin.TabularInline): class BookInline(admin.TabularInline):
@ -2320,14 +2323,15 @@ you have the following models::
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
If you want to allow editing and creating ``Image`` instance on the ``Product`` If you want to allow editing and creating an ``Image`` instance on the
add/change views you can use :class:`~django.contrib.contenttypes.admin.GenericTabularInline` ``Product``, add/change views you can use
:class:`~django.contrib.contenttypes.admin.GenericTabularInline`
or :class:`~django.contrib.contenttypes.admin.GenericStackedInline` (both or :class:`~django.contrib.contenttypes.admin.GenericStackedInline` (both
subclasses of :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin`) subclasses of :class:`~django.contrib.contenttypes.admin.GenericInlineModelAdmin`)
provided by :mod:`~django.contrib.contenttypes.admin`, they implement tabular and provided by :mod:`~django.contrib.contenttypes.admin`. They implement tabular
stacked visual layouts for the forms representing the inline objects and stacked visual layouts for the forms representing the inline objects,
respectively just like their non-generic counterparts and behave just like any respectively, just like their non-generic counterparts. They behave just like
other inline. In your ``admin.py`` for this example app:: any other inline. In your ``admin.py`` for this example app::
from django.contrib import admin from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline from django.contrib.contenttypes.admin import GenericTabularInline