diff options
| author | Yoong Kang Lim <yoongkang.lim@gmail.com> | 2016-01-27 15:34:00 +1100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-02-26 12:27:27 -0500 |
| commit | d5f89ff6e873dbb2890ed05ce2aeae628792c8f7 (patch) | |
| tree | 7a48e29f6aaee10a0be98202729ff6409bfafbb2 /django/forms | |
| parent | 766afc22a1dfa7d34a08de85356b7bc9dba025e7 (diff) | |
Fixed #24974 -- Fixed inheritance of formfield_callback for modelform_factory forms.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/models.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index be9e63d144..4422882315 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -209,7 +209,13 @@ class ModelFormOptions(object): class ModelFormMetaclass(DeclarativeFieldsMetaclass): def __new__(mcs, name, bases, attrs): - formfield_callback = attrs.pop('formfield_callback', None) + base_formfield_callback = None + for b in bases: + if hasattr(b, 'Meta') and hasattr(b.Meta, 'formfield_callback'): + base_formfield_callback = b.Meta.formfield_callback + break + + formfield_callback = attrs.pop('formfield_callback', base_formfield_callback) new_class = super(ModelFormMetaclass, mcs).__new__(mcs, name, bases, attrs) @@ -530,7 +536,8 @@ def modelform_factory(model, form=ModelForm, fields=None, exclude=None, if hasattr(form, 'Meta'): parent = (form.Meta, object) Meta = type(str('Meta'), parent, attrs) - + if formfield_callback: + Meta.formfield_callback = staticmethod(formfield_callback) # Give this new form class a reasonable name. class_name = model.__name__ + str('Form') |
