From 54caca2d34c7cb6807da0a82bcec7b3a679ac104 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 3 Jun 2017 09:50:14 +0200 Subject: [PATCH] Refs #28192 -- Fixed documentation of ChoiceField choices requirement Thanks Tim Graham for noticing the issue. --- docs/ref/forms/fields.txt | 3 ++- tests/forms_tests/field_tests/test_choicefield.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index e6c8fbc4c3..2472f69f48 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -408,7 +408,7 @@ For each field, we describe the default widget used if you don't specify The ``invalid_choice`` error message may contain ``%(value)s``, which will be replaced with the selected choice. - Takes one extra required argument: + Takes one extra argument: .. attribute:: choices @@ -418,6 +418,7 @@ For each field, we describe the default widget used if you don't specify 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. + Defaults to an emtpy list. ``TypedChoiceField`` -------------------- diff --git a/tests/forms_tests/field_tests/test_choicefield.py b/tests/forms_tests/field_tests/test_choicefield.py index fd382e47ca..465cfd83a8 100644 --- a/tests/forms_tests/field_tests/test_choicefield.py +++ b/tests/forms_tests/field_tests/test_choicefield.py @@ -52,6 +52,10 @@ class ChoiceFieldTest(FormFieldAssertionsMixin, SimpleTestCase): with self.assertRaisesMessage(ValidationError, msg): f.clean('6') + def test_choicefield_choices_default(self): + f = ChoiceField() + self.assertEqual(f.choices, []) + def test_choicefield_callable(self): def choices(): return [('J', 'John'), ('P', 'Paul')]