mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #24474 -- Allowed configuring the admin's empty change list value.
This commit is contained in:
parent
0824c02603
commit
72f769f494
11 changed files with 185 additions and 33 deletions
|
@ -205,6 +205,33 @@ subclass::
|
|||
to its documentation for some caveats when time zone support is
|
||||
enabled (:setting:`USE_TZ = True <USE_TZ>`).
|
||||
|
||||
.. attribute:: ModelAdmin.empty_value_display
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
This attribute overrides the default display value for record's fields that
|
||||
are empty (``None``, empty string, etc.). The default value is ``-`` (a
|
||||
dash). For example::
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
class AuthorAdmin(admin.ModelAdmin):
|
||||
empty_value_display = '-empty-'
|
||||
|
||||
You can also override ``empty_value_display`` for all admin pages with
|
||||
:attr:`AdminSite.empty_value_display`, or for specific fields like this::
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
class AuthorAdmin(admin.ModelAdmin):
|
||||
fields = ('name', 'title', 'view_birth_date')
|
||||
|
||||
def view_birth_date(self, obj):
|
||||
return obj.birth_date
|
||||
|
||||
view_birth_date.short_name = 'birth_date'
|
||||
view_birth_date.empty_value_display = '???'
|
||||
|
||||
.. attribute:: ModelAdmin.exclude
|
||||
|
||||
This attribute, if given, should be a list of field names to exclude from
|
||||
|
@ -583,6 +610,33 @@ subclass::
|
|||
class PersonAdmin(admin.ModelAdmin):
|
||||
list_display = ('first_name', 'last_name', 'colored_name')
|
||||
|
||||
* If the value of a field is ``None``, an empty string, or an iterable
|
||||
without elements, Django will display ``-`` (a dash). You can override
|
||||
this with :attr:`AdminSite.empty_value_display`::
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
admin.site.empty_value_display = '(None)'
|
||||
|
||||
You can also use :attr:`AdminSite.empty_value_display`::
|
||||
|
||||
class PersonAdmin(admin.ModelAdmin):
|
||||
empty_value_display = 'unknown'
|
||||
|
||||
Or on a field level::
|
||||
|
||||
class PersonAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'birth_date_view')
|
||||
|
||||
def birth_date_view(self, obj):
|
||||
return obj.birth_date
|
||||
|
||||
birth_date_view.empty_value_display = 'unknown'
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
The ability to customize ``empty_value_display`` was added.
|
||||
|
||||
* If the string given is a method of the model, ``ModelAdmin`` or a
|
||||
callable that returns True or False Django will display a pretty
|
||||
"on" or "off" icon if you give the method a ``boolean`` attribute
|
||||
|
@ -604,7 +658,6 @@ subclass::
|
|||
class PersonAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'born_in_fifties')
|
||||
|
||||
|
||||
* The ``__str__()`` (``__unicode__()`` on Python 2) method is just
|
||||
as valid in ``list_display`` as any other model method, so it's
|
||||
perfectly OK to do this::
|
||||
|
@ -2468,6 +2521,16 @@ Templates can override or extend base admin templates as described in
|
|||
|
||||
Path to a custom template that will be used by the admin site app index view.
|
||||
|
||||
.. attribute:: AdminSite.empty_value_display
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
The string to use for displaying empty values in the admin site's change
|
||||
list. Defaults to a dash. The value can also be overridden on a per
|
||||
``ModelAdmin`` basis and on a custom field within a ``ModelAdmin`` by
|
||||
setting an ``empty_value_display`` attribute on the field. See
|
||||
:attr:`ModelAdmin.empty_value_display` for examples.
|
||||
|
||||
.. attribute:: AdminSite.login_template
|
||||
|
||||
Path to a custom template that will be used by the admin site login view.
|
||||
|
|
|
@ -48,6 +48,13 @@ Minor features
|
|||
changing the ``select_related()`` values used in the admin's changelist query
|
||||
based on the request.
|
||||
|
||||
* :attr:`AdminSite.empty_value_display
|
||||
<django.contrib.admin.AdminSite.empty_value_display>` and
|
||||
:attr:`ModelAdmin.empty_value_display
|
||||
<django.contrib.admin.ModelAdmin.empty_value_display>` were added to override
|
||||
the display of empty values in admin change list. You can also customize the
|
||||
value for each field.
|
||||
|
||||
:mod:`django.contrib.auth`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue