Fixed #24974 -- Fixed inheritance of formfield_callback for modelform_factory forms.

This commit is contained in:
Yoong Kang Lim 2016-01-27 15:34:00 +11:00 committed by Tim Graham
parent 766afc22a1
commit d5f89ff6e8
2 changed files with 31 additions and 2 deletions

View file

@ -2736,6 +2736,28 @@ class FormFieldCallbackTests(SimpleTestCase):
with self.assertRaises(TypeError):
modelform_factory(Person, fields="__all__", formfield_callback='not a function or callable')
def test_inherit_after_custom_callback(self):
def callback(db_field, **kwargs):
if isinstance(db_field, models.CharField):
return forms.CharField(widget=forms.Textarea)
return db_field.formfield(**kwargs)
class BaseForm(forms.ModelForm):
class Meta:
model = Person
fields = '__all__'
NewForm = modelform_factory(Person, form=BaseForm, formfield_callback=callback)
class InheritedForm(NewForm):
pass
for name in NewForm.base_fields.keys():
self.assertEqual(
type(InheritedForm.base_fields[name].widget),
type(NewForm.base_fields[name].widget)
)
class LocalizedModelFormTest(TestCase):
def test_model_form_applies_localize_to_some_fields(self):