From 74e1980cf96eb45079bef464fabdcbe0a6db2423 Mon Sep 17 00:00:00 2001 From: Peter Inglesby Date: Mon, 27 Oct 2014 20:21:59 +0000 Subject: Fixed #13181 -- Added support for callable choices to forms.ChoiceField Thanks vanschelven and expleo for the initial patch. --- docs/ref/forms/fields.txt | 14 ++++++++++---- docs/releases/1.8.txt | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index d7fcef2e75..070ccdf7a8 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -387,10 +387,16 @@ For each field, we describe the default widget used if you don't specify .. attribute:: choices - An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this - field. This argument accepts the same formats as the ``choices`` argument - to a model field. See the :ref:`model field reference documentation on - choices ` for more details. + Either an iterable (e.g., a list or tuple) of 2-tuples to use as + choices for this field, or a callable that returns such an iterable. + This argument accepts the same formats as the ``choices`` argument to a + model field. See the :ref:`model field reference documentation on + choices ` for more details. If the argument is a + callable, it is evaluated each time the field's form is initialized. + + .. versionchanged:: 1.8 + + The ability to pass a callable to ``choices`` was added. ``TypedChoiceField`` ~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index da2e5ae466..d5bae559a7 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -240,6 +240,9 @@ Forms will also update ``UploadedFile.content_type`` with the image's content type as determined by Pillow. +* You can now pass a callable that returns an iterable of choices when + instantiating a :class:`~django.forms.ChoiceField`. + Generic Views ^^^^^^^^^^^^^ -- cgit v1.3