mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #24974 -- Fixed inheritance of formfield_callback for modelform_factory forms.
This commit is contained in:
parent
766afc22a1
commit
d5f89ff6e8
2 changed files with 31 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue