Ticket #6866: validation_and_media-with-basemodelform.diff

File validation_and_media-with-basemodelform.diff, 2.7 KB (added by mrts, 7 years ago)

Use BaseModelForm throughout, accept it as a parent in ModelFormMetaclass

  • django/contrib/admin/options.py

     
    11from django import oldforms, template
    22from django import newforms as forms
    33from django.newforms.formsets import all_valid
    4 from django.newforms.models import _modelform_factory, _inlineformset_factory
     4from django.newforms.models import _modelform_factory, _inlineformset_factory,\
     5        BaseModelForm
    56from django.contrib.contenttypes.models import ContentType
    67from django.contrib.admin import widgets
    78from django.contrib.admin.util import get_deleted_objects
     
    212213    save_on_top = False
    213214    ordering = None
    214215    inlines = []
     216    admin_form = BaseModelForm
    215217
    216218    def __init__(self, model, admin_site):
    217219        self.model = model
     
    318320            fields = flatten_fieldsets(self.declared_fieldsets)
    319321        else:
    320322            fields = None
    321         return _modelform_factory(self.model, fields=fields, formfield_callback=self.formfield_for_dbfield)
     323        return _modelform_factory(self.model, form=self.admin_form,
     324                fields=fields, formfield_callback=self.formfield_for_dbfield)
    322325
    323326    def get_formsets(self, request, obj=None):
    324327        for inline in self.inline_instances:
  • django/newforms/models.py

     
    217217    def __new__(cls, name, bases, attrs,
    218218                formfield_callback=lambda f: f.formfield()):
    219219        try:
    220             parents = [b for b in bases if issubclass(b, ModelForm)]
     220            parents = [b for b in bases if issubclass(b, BaseModelForm)]
    221221        except NameError:
    222222            # We are defining ModelForm itself.
    223223            parents = None
     
    277277    __metaclass__ = ModelFormMetaclass
    278278
    279279# XXX: This API *will* change. Use at your own risk.
    280 def _modelform_factory(model, form=BaseForm, fields=None, exclude=None,
     280def _modelform_factory(model, form=BaseModelForm, fields=None, exclude=None,
    281281                       formfield_callback=lambda f: f.formfield()):
    282282    # HACK: we should be able to construct a ModelForm without creating
    283283    # and passing in a temporary inner class
     
    287287    setattr(Meta, 'fields', fields)
    288288    setattr(Meta, 'exclude', exclude)
    289289    class_name = model.__name__ + 'Form'
    290     return ModelFormMetaclass(class_name, (ModelForm,), {'Meta': Meta},
     290    return ModelFormMetaclass(class_name, (form,), {'Meta': Meta},
    291291                              formfield_callback=formfield_callback)
    292292
    293293
Back to Top