mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #24974 -- Fixed inheritance of formfield_callback for modelform_factory forms.
This commit is contained in:
committed by
Tim Graham
parent
766afc22a1
commit
d5f89ff6e8
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user