diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index a2d2857f0f..9fe6dd3c54 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -462,7 +462,7 @@ class Field(object): for k in kwargs.keys(): if k not in ('coerce', 'empty_value', 'choices', 'required', 'widget', 'label', 'initial', 'help_text', - 'error_messages'): + 'error_messages', 'show_hidden_initial'): del kwargs[k] defaults.update(kwargs) return form_class(**defaults) diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py index 2ac0af3267..d7591d5a22 100644 --- a/tests/regressiontests/model_fields/tests.py +++ b/tests/regressiontests/model_fields/tests.py @@ -26,6 +26,20 @@ if Image: TwoImageFieldTests +class BasicFieldTests(django.test.TestCase): + def test_show_hidden_initial(self): + """ + Regression test for #12913. Make sure fields with choices respect + show_hidden_initial as a kwarg to models.Field.formfield() + """ + choices = [(0, 0), (1, 1)] + model_field = models.Field(choices=choices) + form_field = model_field.formfield(show_hidden_initial=True) + self.assertTrue(form_field.show_hidden_initial) + + form_field = model_field.formfield(show_hidden_initial=False) + self.assertFalse(form_field.show_hidden_initial) + class DecimalFieldTests(django.test.TestCase): def test_to_python(self): f = models.DecimalField(max_digits=4, decimal_places=2)