diff options
| author | Loek van Gent <loek@1procentclub.nl> | 2015-03-13 11:08:03 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-04-08 20:27:01 -0400 |
| commit | 72f769f494822981db6df9524b92a2d86f8e69fe (patch) | |
| tree | 85059cd2e6cf801c0e0bec8f8bbc2ebff5e4792a /docs/ref | |
| parent | 0824c026035b75b3aa32ad9b19b700fed487de27 (diff) | |
Fixed #24474 -- Allowed configuring the admin's empty change list value.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 4b11fed58a..17577377d3 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -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. |
