Ticket #6866: easy_validation_and_media-with-fixed-inlines.diff

File easy_validation_and_media-with-fixed-inlines.diff, 3.7 KB (added by mrts, 17 years ago)

Fixes inline forms as well.

  • django/contrib/admin/options.py

     
    22from django import newforms as forms
    33from django.newforms.formsets import all_valid
    44from django.newforms.models import _modelform_factory, _inlineformset_factory
     5# don't mess with ModelForm name defined in other places except line 217
     6from django.newforms.models import ModelForm as ModelFormClass
    57from django.contrib.contenttypes.models import ContentType
    68from django.contrib.admin import widgets
    79from django.contrib.admin.util import get_deleted_objects
     
    212214    save_on_top = False
    213215    ordering = None
    214216    inlines = []
     217    admin_form = ModelFormClass
    215218
    216219    def __init__(self, model, admin_site):
    217220        self.model = model
     
    308311        """
    309312        Returns a Form class for use in the admin add view. This is used by
    310313        add_view and change_view.
    311        
    312         Note that if you override this method, your form will *not*
    313         automatically get the custom admin widgets. raw_id_fields, fields,
    314         fieldsets, filter_vertical, and filter_horizonal will not apply to
    315         your form. You will have manually specify those widgets.
    316314        """
    317315        if self.declared_fieldsets:
    318316            fields = flatten_fieldsets(self.declared_fieldsets)
    319317        else:
    320318            fields = None
    321         return _modelform_factory(self.model, fields=fields, formfield_callback=self.formfield_for_dbfield)
     319        return _modelform_factory(self.model, form=self.admin_form, fields=fields, formfield_callback=self.formfield_for_dbfield)
    322320
    323321    def get_formsets(self, request, obj=None):
    324322        for inline in self.inline_instances:
  • django/newforms/models.py

     
    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,
     280# bugfix by brosner: http://dpaste.com/40940/
     281def _modelform_factory(model, form=ModelForm, fields=None, exclude=None,
    281282                       formfield_callback=lambda f: f.formfield()):
    282283    # HACK: we should be able to construct a ModelForm without creating
    283284    # and passing in a temporary inner class
     
    287288    setattr(Meta, 'fields', fields)
    288289    setattr(Meta, 'exclude', exclude)
    289290    class_name = model.__name__ + 'Form'
    290     return ModelFormMetaclass(class_name, (ModelForm,), {'Meta': Meta},
     291    return ModelFormMetaclass(class_name, (form,), {'Meta': Meta},
    291292                              formfield_callback=formfield_callback)
    292293
    293294
     
    360361        super(BaseModelFormSet, self).add_fields(form, index)
    361362
    362363# XXX: Use at your own risk. This API *will* change.
    363 def _modelformset_factory(model, form=BaseModelForm, formfield_callback=lambda f: f.formfield(),
     364def _modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(),
    364365                          formset=BaseModelFormSet,
    365366                          extra=1, can_delete=False, can_order=False,
    366367                          fields=None, exclude=None):
     
    427428
    428429
    429430# XXX: This API *will* change. Use at your own risk.
    430 def _inlineformset_factory(parent_model, model, form=BaseModelForm, fk_name=None,
     431def _inlineformset_factory(parent_model, model, form=ModelForm, fk_name=None,
    431432                           fields=None, exclude=None,
    432433                           extra=3, can_order=False, can_delete=True,
    433434                           formfield_callback=lambda f: f.formfield()):
Back to Top