Ticket #6866: easy_validation_and_media.diff
File easy_validation_and_media.diff, 2.8 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
2 2 from django import newforms as forms 3 3 from django.newforms.formsets import all_valid 4 4 from django.newforms.models import _modelform_factory, _inlineformset_factory 5 # don't mess with ModelForm name defined in other places except line 217 6 from django.newforms.models import ModelForm as ModelFormClass 5 7 from django.contrib.contenttypes.models import ContentType 6 8 from django.contrib.admin import widgets 7 9 from django.contrib.admin.util import get_deleted_objects … … 212 214 save_on_top = False 213 215 ordering = None 214 216 inlines = [] 217 admin_form = ModelFormClass 215 218 216 219 def __init__(self, model, admin_site): 217 220 self.model = model … … 308 311 """ 309 312 Returns a Form class for use in the admin add view. This is used by 310 313 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 to315 your form. You will have manually specify those widgets.316 314 """ 317 315 if self.declared_fieldsets: 318 316 fields = flatten_fieldsets(self.declared_fieldsets) 319 317 else: 320 318 fields = None 321 return _modelform_factory(self.model, f ields=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) 322 320 323 321 def get_formsets(self, request, obj=None): 324 322 for inline in self.inline_instances: -
django/newforms/models.py
277 277 __metaclass__ = ModelFormMetaclass 278 278 279 279 # 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/ 281 def _modelform_factory(model, form=ModelForm, fields=None, exclude=None, 281 282 formfield_callback=lambda f: f.formfield()): 282 283 # HACK: we should be able to construct a ModelForm without creating 283 284 # and passing in a temporary inner class … … 287 288 setattr(Meta, 'fields', fields) 288 289 setattr(Meta, 'exclude', exclude) 289 290 class_name = model.__name__ + 'Form' 290 return ModelFormMetaclass(class_name, ( ModelForm,), {'Meta': Meta},291 return ModelFormMetaclass(class_name, (form,), {'Meta': Meta}, 291 292 formfield_callback=formfield_callback) 292 293 293 294