Opened 14 years ago

Closed 14 years ago

Last modified 13 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

Description

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 14 years ago.

Download all attachments as: .zip

Change History (4)

by Satoru Logic, 14 years ago

comment:1 by Matthias Kestenholz, 14 years ago

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 by Russell Keith-Magee, 14 years ago

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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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