Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.1.X] Fixed #12913. Fields with choices now respect show_hidden_ini…

…tial as a keyword argument to formfield. Backport of r12696 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12697 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e8c768910afd441aa39759de27939eee5d141219 1 parent 8a8366d
@jkocherhans jkocherhans authored
View
2  django/db/models/fields/__init__.py
@@ -339,7 +339,7 @@ def formfield(self, form_class=forms.CharField, **kwargs):
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)
View
14 tests/regressiontests/model_fields/tests.py
@@ -26,6 +26,20 @@
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)
Please sign in to comment.
Something went wrong with that request. Please try again.