Ticket #10776: 10776.diff

File 10776.diff, 10.0 KB (added by timo, 6 years ago)

also added some metadata targets to docs/contrib/admin/index.txt

  • docs/ref/models/fields.txt

     
    689689
    690690Implies setting :attr:`Field.db_index` to ``True``.
    691691
     692It is often useful to automatically prepopulate a SlugField based on the value
     693of some other value.  You can do this automatically in the admin using
     694:attr:`~django.contrib.admin.ModelAdmin.prepopulated_fields`.
     695
    692696``SmallIntegerField``
    693697---------------------
    694698
  • docs/ref/contrib/admin/index.txt

     
    77.. module:: django.contrib.admin
    88   :synopsis: Django's admin site.
    99
     10.. currentmodule:: django.contrib.admin
     11
    1012One of the most powerful parts of Django is the automatic admin interface. It
    1113reads metadata in your model to provide a powerful and production-ready
    1214interface that content producers can immediately use to start adding content to
     
    5557``ModelAdmin`` objects
    5658======================
    5759
     60.. class:: ModelAdmin
     61
    5862The ``ModelAdmin`` class is the representation of a model in the admin
    5963interface. These are stored in a file named ``admin.py`` in your application.
    6064Let's take a look at a very simple example of the ``ModelAdmin``::
     
    9094    class AuthorAdmin(admin.ModelAdmin):
    9195        date_hierarchy = 'pub_date'
    9296
    93 ``date_hierarchy``
    94 ~~~~~~~~~~~~~~~~~~
     97.. attribute:: ModelAdmin.date_hierarchy
    9598
    9699Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField`` in
    97100your model, and the change list page will include a date-based drilldown
     
    101104
    102105    date_hierarchy = 'pub_date'
    103106
    104 ``form``
    105 ~~~~~~~~
     107.. attribute:: ModelAdmin.form
    106108
    107109By default a ``ModelForm`` is dynamically created for your model. It is used
    108110to create the form presented on both the add/change pages. You can easily
     
    111113
    112114For an example see the section `Adding custom validation to the admin`_.
    113115
    114 ``fieldsets``
    115 ~~~~~~~~~~~~~
     116.. attribute:: ModelAdmin.fieldsets
    116117
    117118Set ``fieldsets`` to control the layout of admin "add" and "change" pages.
    118119
     
    191192        ``django.utils.html.escape()`` to escape any HTML special
    192193        characters.
    193194
    194 ``fields``
    195 ~~~~~~~~~~
     195.. attribute:: ModelAdmin.fields
    196196
    197197Use this option as an alternative to ``fieldsets`` if the layout does not
    198198matter and if you want to only show a subset of the available fields in the
     
    211211    dictionary key that is within the ``fieldsets`` option, as described in
    212212    the previous section.
    213213
    214 ``exclude``
    215 ~~~~~~~~~~~
     214.. attribute:: ModelAdmin.exclude
    216215
    217216This attribute, if given, should be a list of field names to exclude from the
    218217form.
     
    237236``birth_date``, the forms resulting from the above declarations will contain
    238237exactly the same fields.
    239238
    240 ``filter_horizontal``
    241 ~~~~~~~~~~~~~~~~~~~~~
     239.. attribute:: ModelAdmin.filter_horizontal
    242240
    243241Use a nifty unobtrusive JavaScript "filter" interface instead of the
    244242usability-challenged ``<select multiple>`` in the admin form. The value is a
    245243list of fields that should be displayed as a horizontal filter interface. See
    246244``filter_vertical`` to use a vertical interface.
    247245
    248 ``filter_vertical``
    249 ~~~~~~~~~~~~~~~~~~~
     246.. attribute:: ModelAdmin.filter_vertical
    250247
    251248Same as ``filter_horizontal``, but is a vertical display of the filter
    252249interface.
    253250
    254 ``list_display``
    255 ~~~~~~~~~~~~~~~~
     251.. attribute:: ModelAdmin.list_display
    256252
    257253Set ``list_display`` to control which fields are displayed on the change list
    258254page of the admin.
     
    389385      The above will tell Django to order by the ``first_name`` field when
    390386      trying to sort by ``colored_first_name`` in the admin.
    391387
    392 ``list_display_links``
    393 ~~~~~~~~~~~~~~~~~~~~~~
     388.. attribute:: ModelAdmin.list_display_links
    394389
    395390Set ``list_display_links`` to control which fields in ``list_display`` should
    396391be linked to the "change" page for an object.
     
    415410
    416411.. _admin-list-editable:
    417412
    418 ``list_editable``
    419 ~~~~~~~~~~~~~~~~~
     413.. attribute:: ModelAdmin.list_editable
    420414
    421415.. versionadded:: 1.1
    422416
     
    441435
    442436    You'll get a validation error if any of these rules are broken.
    443437
    444 ``list_filter``
    445 ~~~~~~~~~~~~~~~
     438.. attribute:: ModelAdmin.list_filter
    446439
    447440Set ``list_filter`` to activate filters in the right sidebar of the change list
    448441page of the admin. This should be a list of field names, and each specified
     
    462455
    463456(This example also has ``search_fields`` defined. See below.)
    464457
    465 ``list_per_page``
    466 ~~~~~~~~~~~~~~~~~
     458.. attribute:: ModelAdmin.list_per_page
    467459
    468460Set ``list_per_page`` to control how many items appear on each paginated admin
    469461change list page. By default, this is set to ``100``.
    470462
    471 ``list_select_related``
    472 ~~~~~~~~~~~~~~~~~~~~~~~
     463.. attribute:: ModelAdmin.list_select_related
    473464
    474465Set ``list_select_related`` to tell Django to use ``select_related()`` in
    475466retrieving the list of objects on the admin change list page. This can save you
     
    483474For more on ``select_related()``, see
    484475:ref:`the select_related() docs <select-related>`.
    485476
    486 ``inlines``
    487 ~~~~~~~~~~~
     477.. attribute:: ModelAdmin.inlines
    488478
    489479See ``InlineModelAdmin`` objects below.
    490480
    491 ``ordering``
    492 ~~~~~~~~~~~~
     481.. attribute:: ModelAdmin.ordering
    493482
    494483Set ``ordering`` to specify how objects on the admin change list page should be
    495484ordered. This should be a list or tuple in the same format as a model's
     
    502491    Django will only honor the first element in the list/tuple; any others
    503492    will be ignored.
    504493
    505 ``prepopulated_fields``
    506 ~~~~~~~~~~~~~~~~~~~~~~~
     494.. attribute:: ModelAdmin.prepopulated_fields
    507495
    508496Set ``prepopulated_fields`` to a dictionary mapping field names to the fields
    509497it should prepopulate from::
     
    521509``prepopulated_fields`` doesn't accept ``DateTimeField``, ``ForeignKey``, nor
    522510``ManyToManyField`` fields.
    523511
    524 ``radio_fields``
    525 ~~~~~~~~~~~~~~~~
     512.. attribute:: ModelAdmin.radio_fields
    526513
    527514By default, Django's admin uses a select-box interface (<select>) for
    528515fields that are ``ForeignKey`` or have ``choices`` set. If a field is present
     
    538525Don't include a field in ``radio_fields`` unless it's a ``ForeignKey`` or has
    539526``choices`` set.
    540527
    541 ``raw_id_fields``
    542 ~~~~~~~~~~~~~~~~~
     528.. attribute:: ModelAdmin.raw_id_fields
    543529
    544530By default, Django's admin uses a select-box interface (<select>) for
    545531fields that are ``ForeignKey``. Sometimes you don't want to incur the
     
    552538    class ArticleAdmin(admin.ModelAdmin):
    553539        raw_id_fields = ("newspaper",)
    554540
    555 ``save_as``
    556 ~~~~~~~~~~~
     541.. attribute:: ModelAdmin.save_as
    557542
    558543Set ``save_as`` to enable a "save as" feature on admin change forms.
    559544
     
    566551
    567552By default, ``save_as`` is set to ``False``.
    568553
    569 ``save_on_top``
    570 ~~~~~~~~~~~~~~~
     554.. attribute:: ModelAdmin.save_on_top
    571555
    572556Set ``save_on_top`` to add save buttons across the top of your admin change
    573557forms.
     
    577561
    578562By default, ``save_on_top`` is set to ``False``.
    579563
    580 ``search_fields``
    581 ~~~~~~~~~~~~~~~~~
     564.. attribute:: ModelAdmin.search_fields
    582565
    583566Set ``search_fields`` to enable a search box on the admin change list page.
    584567This should be set to a list of field names that will be searched whenever
     
    635618    Performs a full-text match. This is like the default search method but uses
    636619    an index. Currently this is only available for MySQL.
    637620
    638 ``formfield_overrides``
    639 ~~~~~~~~~~~~~~~~~~~~~~~
     621.. attribute:: ModelAdmin.formfield_overrides
    640622
    641623This provides a quick-and-dirty way to override some of the
    642624:class:`~django.forms.Field` options for use in the admin.
     
    676658    that have ``raw_id_fields`` or ``radio_fields`` set. That's because
    677659    ``raw_id_fields`` and ``radio_fields`` imply custom widgets of their own.
    678660
    679 ``actions``
    680 ~~~~~~~~~~~
     661.. attribute:: ModelAdmin.actions
    681662
    682663A list of actions to make available on the change list page. See
    683664:ref:`ref-contrib-admin-actions` for details.
    684665
    685 ``actions_on_top``, ``actions_on_bottom``
    686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     666.. attribute:: ModelAdmin.actions_on_top
     667.. attribute:: ModelAdmin.actions_on_bottom
    687668
    688669Controls where on the page the actions bar appears. By default, the admin
    689670changelist displays actions at the top of the page (``actions_on_top = True;
     
    692673``ModelAdmin`` methods
    693674----------------------
    694675
    695 ``save_model(self, request, obj, form, change)``
    696 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     676.. method:: ModelAdmin.save_model(self, request, obj, form, change)
    697677
    698678The ``save_model`` method is given the ``HttpRequest``, a model instance,
    699679a ``ModelForm`` instance and a boolean value based on whether it is adding or
     
    706686            obj.user = request.user
    707687            obj.save()
    708688
    709 ``save_formset(self, request, form, formset, change)``
    710 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     689.. method:: ModelAdmin.save_formset(self, request, form, formset, change)
    711690
    712691The ``save_formset`` method is given the ``HttpRequest``, the parent
    713692``ModelForm`` instance and a boolean value based on whether it is adding or
     
    724703                instance.save()
    725704            formset.save_m2m()
    726705
    727 ``get_urls(self)``
    728 ~~~~~~~~~~~~~~~~~~~
     706.. method:: ModelAdmin.get_urls(self)
    729707
    730708.. versionadded:: 1.1
    731709
     
    769747
    770748This wrapping will protect ``self.my_view`` from unauthorized access.
    771749
    772 ``formfield_for_foreignkey(self, db_field, request, **kwargs)``
    773 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     750.. method:: ModelAdmin.formfield_for_foreignkey(self, db_field, request, **kwargs)
    774751
    775752.. versionadded:: 1.1
    776753
     
    12751252.. versionadded:: 1.1
    12761253
    12771254It possible to add additional views to the admin site in the same way one can
    1278 add them to ``ModelAdmins``.  This by using the ``get_urls()`` method on an
    1279 AdminSite in the same way as `described above`__
    1280 
    1281 __ `get_urls(self)`_
     1255add them to ``ModelAdmins``.  This by using the :meth:`~django.contrib.admin.ModelAdmin.get_urls()` method on an
     1256AdminSite.
Back to Top