Opened 11 years ago

Closed 10 years ago

Last modified 9 years ago

#13918 closed (fixed)

[patch] Simplify implementation of `get_model_and_form_class`

Reported by: Satoru Logic Owned by: Satoru Logic
Component: Generic views Version: 1.2
Severity: Keywords:
Cc: liaoxuecong@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In django.views.generic.create_update.get_model_and_form_class, a form_class is constructed this way

        # The inner Meta class fails if model = model is used for some reason.
        tmp_model = model
        # TODO: we should be able to construct a ModelForm without creating
        # and passing in a temporary inner class.
        class Meta:
            model = tmp_model
        class_name = model.__name__ + 'Form'
        form_class = ModelFormMetaclass(class_name, (ModelForm,), {'Meta': Meta})

When I looked into the django.forms.models module I found a function called modelform_factory that can make this much simpler:

form_class = modelform_factory(model)

Attachments (1)

13918_simpler_get_model_form.diff (1.2 KB) - added by Satoru Logic 11 years ago.

Download all attachments as: .zip

Change History (4)

Changed 11 years ago by Satoru Logic

comment:1 Changed 10 years ago by Matthias Kestenholz

Triage Stage: UnreviewedAccepted

Even though there's an upcoming refactoring of generic views using class-based views I think this patch makes sense, if only to avoid repetition.

comment:2 Changed 10 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.

comment:3 Changed 9 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top