Ticket #6866: validation_and_media-with-basemodelform.diff
File validation_and_media-with-basemodelform.diff, 2.7 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
1 1 from django import oldforms, template 2 2 from django import newforms as forms 3 3 from django.newforms.formsets import all_valid 4 from django.newforms.models import _modelform_factory, _inlineformset_factory 4 from django.newforms.models import _modelform_factory, _inlineformset_factory,\ 5 BaseModelForm 5 6 from django.contrib.contenttypes.models import ContentType 6 7 from django.contrib.admin import widgets 7 8 from django.contrib.admin.util import get_deleted_objects … … 212 213 save_on_top = False 213 214 ordering = None 214 215 inlines = [] 216 admin_form = BaseModelForm 215 217 216 218 def __init__(self, model, admin_site): 217 219 self.model = model … … 318 320 fields = flatten_fieldsets(self.declared_fieldsets) 319 321 else: 320 322 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) 322 325 323 326 def get_formsets(self, request, obj=None): 324 327 for inline in self.inline_instances: -
django/newforms/models.py
217 217 def __new__(cls, name, bases, attrs, 218 218 formfield_callback=lambda f: f.formfield()): 219 219 try: 220 parents = [b for b in bases if issubclass(b, ModelForm)]220 parents = [b for b in bases if issubclass(b, BaseModelForm)] 221 221 except NameError: 222 222 # We are defining ModelForm itself. 223 223 parents = None … … 277 277 __metaclass__ = ModelFormMetaclass 278 278 279 279 # XXX: This API *will* change. Use at your own risk. 280 def _modelform_factory(model, form=Base Form, fields=None, exclude=None,280 def _modelform_factory(model, form=BaseModelForm, fields=None, exclude=None, 281 281 formfield_callback=lambda f: f.formfield()): 282 282 # HACK: we should be able to construct a ModelForm without creating 283 283 # and passing in a temporary inner class … … 287 287 setattr(Meta, 'fields', fields) 288 288 setattr(Meta, 'exclude', exclude) 289 289 class_name = model.__name__ + 'Form' 290 return ModelFormMetaclass(class_name, ( ModelForm,), {'Meta': Meta},290 return ModelFormMetaclass(class_name, (form,), {'Meta': Meta}, 291 291 formfield_callback=formfield_callback) 292 292 293 293