mirror of https://github.com/django/django.git
Fixed #12913. Fields with choices now respect show_hidden_initial as a keyword argument to formfield. Thanks, semenov.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12696 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9a67543c3e
commit
686dac03b7
|
@ -462,7 +462,7 @@ class Field(object):
|
||||||
for k in kwargs.keys():
|
for k in kwargs.keys():
|
||||||
if k not in ('coerce', 'empty_value', 'choices', 'required',
|
if k not in ('coerce', 'empty_value', 'choices', 'required',
|
||||||
'widget', 'label', 'initial', 'help_text',
|
'widget', 'label', 'initial', 'help_text',
|
||||||
'error_messages'):
|
'error_messages', 'show_hidden_initial'):
|
||||||
del kwargs[k]
|
del kwargs[k]
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
return form_class(**defaults)
|
return form_class(**defaults)
|
||||||
|
|
|
@ -26,6 +26,20 @@ if Image:
|
||||||
TwoImageFieldTests
|
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):
|
class DecimalFieldTests(django.test.TestCase):
|
||||||
def test_to_python(self):
|
def test_to_python(self):
|
||||||
f = models.DecimalField(max_digits=4, decimal_places=2)
|
f = models.DecimalField(max_digits=4, decimal_places=2)
|
||||||
|
|
Loading…
Reference in New Issue