Ticket #13918: 13918_simpler_get_model_form.diff

File 13918_simpler_get_model_form.diff, 1.2 KB (added by Satoru Logic, 14 years ago)
  • create_update.py

     
    1 from django.forms.models import ModelFormMetaclass, ModelForm
     1from django.forms.models import  modelform_factory
    22from django.template import RequestContext, loader
    33from django.http import Http404, HttpResponse, HttpResponseRedirect
    44from django.core.xheaders import populate_xheaders
     
    3333    if form_class:
    3434        return form_class._meta.model, form_class
    3535    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)
    4437        return model, form_class
    4538    raise GenericViewError("Generic view must be called with either a model or"
    4639                           " form_class argument.")
Back to Top