From 1123f4551158b7fc65d3bd88c375a4517dcd0720 Mon Sep 17 00:00:00 2001 From: Alex Couper Date: Sat, 20 Jul 2013 21:49:33 +0000 Subject: Fixed #20649 -- Allowed blank field display to be defined in the initial list of choices. --- docs/ref/models/fields.txt | 19 ++++++++++++++----- docs/releases/1.7.txt | 5 +++++ 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index 869996643f..736a836924 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -152,11 +152,20 @@ method to retrieve the human-readable name for the field's current value. See :meth:`~django.db.models.Model.get_FOO_display` in the database API documentation. -Finally, note that choices can be any iterable object -- not necessarily a list -or tuple. This lets you construct choices dynamically. But if you find yourself -hacking :attr:`~Field.choices` to be dynamic, you're probably better off using a -proper database table with a :class:`ForeignKey`. :attr:`~Field.choices` is -meant for static data that doesn't change much, if ever. +Note that choices can be any iterable object -- not necessarily a list or tuple. +This lets you construct choices dynamically. But if you find yourself hacking +:attr:`~Field.choices` to be dynamic, you're probably better off using a proper +database table with a :class:`ForeignKey`. :attr:`~Field.choices` is meant for +static data that doesn't change much, if ever. + +.. versionadded:: 1.7 + +Unless :attr:`blank=False` is set on the field along with a +:attr:`~Field.default` then a label containing ``"---------"`` will be rendered +with the select box. To override this behavior, add a tuple to ``choices`` +containing ``None``; e.g. ``(None, 'Your String For Display')``. +Alternatively, you can use an empty string instead of ``None`` where this makes +sense - such as on a :class:`~django.db.models.CharField`. ``db_column`` ------------- diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index b75fd89f4c..c47a392dff 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -105,6 +105,11 @@ Minor features ` method to more easily customize the login policy. +* :attr:`Field.choices` now allows you to + customize the "empty choice" label by including a tuple with an empty string + or ``None`` for the key and the custom label as the value. The default blank + option ``"----------"`` will be omitted in this case. + Backwards incompatible changes in 1.7 ===================================== -- cgit v1.3