#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)
Change History (4)
by , 14 years ago
Attachment: | 13918_simpler_get_model_form.diff added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.
Note:
See TracTickets
for help on using tickets.
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.