summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorLoek van Gent <loek@1procentclub.nl>2015-03-13 11:08:03 +0100
committerTim Graham <timograham@gmail.com>2015-06-04 21:06:26 -0400
commit0207bdd2d4157c542c981264c86706b78ca246e9 (patch)
tree3664db1ac08dda620077c14cfbb1c6da548b0529 /docs
parent40f0a84cb151669313faadf857aaddd18d39aaeb (diff)
Fixed #24474 -- Allowed configuring the admin's empty change list value.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/admin/index.txt65
-rw-r--r--docs/releases/1.9.txt6
2 files changed, 70 insertions, 1 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 540ed42e12..091967c796 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::
@@ -2474,6 +2527,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.
diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt
index 4047785ef1..ecd2af6ddc 100644
--- a/docs/releases/1.9.txt
+++ b/docs/releases/1.9.txt
@@ -52,6 +52,12 @@ Minor features
applications for the current user, has been added to the
:meth:`AdminSite.each_context() <django.contrib.admin.AdminSite.each_context>`
method.
+* :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`
^^^^^^^^^^^^^^^^^^^^^^^^^^