Fixed #27969 -- Fixed models.Field.formfield() setting 'disabled' for fields with choices.

This commit is contained in:
Kapil Garg 2017-03-22 04:59:14 +05:30 committed by Tim Graham
parent 075f13e44f
commit 7e09fa7f51
2 changed files with 7 additions and 1 deletions

View File

@ -850,7 +850,7 @@ class Field(RegisterLookupMixin):
for k in list(kwargs): for k in list(kwargs):
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', 'show_hidden_initial'): 'error_messages', 'show_hidden_initial', 'disabled'):
del kwargs[k] del kwargs[k]
defaults.update(kwargs) defaults.update(kwargs)
if form_class is None: if form_class is None:

View File

@ -54,6 +54,12 @@ class BasicFieldTests(TestCase):
klass = forms.TypedMultipleChoiceField klass = forms.TypedMultipleChoiceField
self.assertIsInstance(field.formfield(choices_form_class=klass), klass) self.assertIsInstance(field.formfield(choices_form_class=klass), klass)
def test_formfield_disabled(self):
"""Field.formfield() sets disabled for fields with choices."""
field = models.CharField(choices=[('a', 'b')])
form_field = field.formfield(disabled=True)
self.assertIs(form_field.disabled, True)
def test_field_str(self): def test_field_str(self):
f = models.Field() f = models.Field()
self.assertEqual(str(f), '<django.db.models.fields.Field>') self.assertEqual(str(f), '<django.db.models.fields.Field>')