summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
authorYoong Kang Lim <yoongkang.lim@gmail.com>2016-01-27 15:34:00 +1100
committerTim Graham <timograham@gmail.com>2016-02-26 12:27:27 -0500
commitd5f89ff6e873dbb2890ed05ce2aeae628792c8f7 (patch)
tree7a48e29f6aaee10a0be98202729ff6409bfafbb2 /tests/model_forms
parent766afc22a1dfa7d34a08de85356b7bc9dba025e7 (diff)
Fixed #24974 -- Fixed inheritance of formfield_callback for modelform_factory forms.
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index a2e7c66419..873699f921 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -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):