diff options
| author | Tom Carrick <tom@carrick.eu> | 2023-04-04 15:11:11 +0100 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2024-02-05 21:42:04 -0300 |
| commit | 4ade8386ebfeb7a781dc2b62542c1cf5f8b9ddaf (patch) | |
| tree | 97263c4f927ad797883bba77db95c6dee6041df4 /docs | |
| parent | 3580b47ed31ec85ae89b13618f36bb463e97acc8 (diff) | |
Fixed #10743 -- Allowed lookups for related fields in ModelAdmin.list_display.
Co-authored-by: Alex Garcia <me@alexoteiza.com>
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Co-authored-by: Nina Menezes <https://github.com/nmenezes0>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/checks.txt | 6 | ||||
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 20 | ||||
| -rw-r--r-- | docs/releases/5.1.txt | 3 |
3 files changed, 20 insertions, 9 deletions
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index f0eeaca268..cf0ab32efa 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -726,9 +726,9 @@ with the admin site: * **admin.E106**: The value of ``<InlineModelAdmin class>.model`` must be a ``Model``. * **admin.E107**: The value of ``list_display`` must be a list or tuple. -* **admin.E108**: The value of ``list_display[n]`` refers to ``<label>``, - which is not a callable, an attribute of ``<ModelAdmin class>``, or an - attribute or method on ``<model>``. +* **admin.E108**: The value of ``list_display[n]`` refers to ``<label>``, which + is not a callable or attribute of ``<ModelAdmin class>``, or an attribute, + method, or field on ``<model>``. * **admin.E109**: The value of ``list_display[n]`` must not be a many-to-many field or a reverse foreign key. * **admin.E110**: The value of ``list_display_links`` must be a list, a tuple, diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index e85ba9c36a..e0e57b9fc0 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -315,9 +315,9 @@ subclass:: For more complex layout needs, see the :attr:`~ModelAdmin.fieldsets` option. The ``fields`` option accepts the same types of values as - :attr:`~ModelAdmin.list_display`, except that callables aren't accepted. - Names of model and model admin methods will only be used if they're listed - in :attr:`~ModelAdmin.readonly_fields`. + :attr:`~ModelAdmin.list_display`, except that callables and ``__`` lookups + for related fields aren't accepted. Names of model and model admin methods + will only be used if they're listed in :attr:`~ModelAdmin.readonly_fields`. 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 @@ -565,7 +565,7 @@ subclass:: If you don't set ``list_display``, the admin site will display a single column that displays the ``__str__()`` representation of each object. - There are four types of values that can be used in ``list_display``. All + There are five types of values that can be used in ``list_display``. All but the simplest may use the :func:`~django.contrib.admin.display` decorator, which is used to customize how the field is presented: @@ -574,6 +574,11 @@ subclass:: class PersonAdmin(admin.ModelAdmin): list_display = ["first_name", "last_name"] + * The name of a related field, using the ``__`` notation. For example:: + + class PersonAdmin(admin.ModelAdmin): + list_display = ["city__name"] + * A callable that accepts one argument, the model instance. For example:: @admin.display(description="Name") @@ -614,6 +619,11 @@ subclass:: class PersonAdmin(admin.ModelAdmin): list_display = ["name", "decade_born_in"] + .. versionchanged:: 5.1 + + Support for using ``__`` lookups was added, when targeting related + fields. + A few special cases to note about ``list_display``: * If the field is a ``ForeignKey``, Django will display the @@ -831,7 +841,7 @@ subclass:: * Django will try to interpret every element of ``list_display`` in this order: - * A field of the model. + * A field of the model or from a related field. * A callable. * A string representing a ``ModelAdmin`` attribute. * A string representing a model attribute. diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt index 1d014ceb21..701d686532 100644 --- a/docs/releases/5.1.txt +++ b/docs/releases/5.1.txt @@ -32,7 +32,8 @@ Minor features :mod:`django.contrib.admin` ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -* ... +* :attr:`.ModelAdmin.list_display` now supports using ``__`` lookups to list + fields from related models. :mod:`django.contrib.admindocs` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
