Ticket #13918: 13918_simpler_get_model_form.diff
File 13918_simpler_get_model_form.diff, 1.2 KB (added by , 14 years ago) |
---|
-
create_update.py
1 from django.forms.models import ModelFormMetaclass, ModelForm1 from django.forms.models import modelform_factory 2 2 from django.template import RequestContext, loader 3 3 from django.http import Http404, HttpResponse, HttpResponseRedirect 4 4 from django.core.xheaders import populate_xheaders … … 33 33 if form_class: 34 34 return form_class._meta.model, form_class 35 35 if model: 36 # The inner Meta class fails if model = model is used for some reason. 37 tmp_model = model 38 # TODO: we should be able to construct a ModelForm without creating 39 # and passing in a temporary inner class. 40 class Meta: 41 model = tmp_model 42 class_name = model.__name__ + 'Form' 43 form_class = ModelFormMetaclass(class_name, (ModelForm,), {'Meta': Meta}) 36 form_class = modelform_factory(model) 44 37 return model, form_class 45 38 raise GenericViewError("Generic view must be called with either a model or" 46 39 " form_class argument.")