Opened 17 years ago
Last modified 5 years ago
#10305 new New feature
change the way ModelForms are instantiated in add_view, change_view — at Version 5
| Reported by: | tangc | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | add_view, change_view, ModelForm |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
add_view and change_view have the following code:
ModelForm = self.get_form(request) ... form = ModelForm(request.POST, request.FILES)
or:
form = ModelForm(initial=initial)
or:
form = ModelForm(request.POST, request.FILES, instance=obj)
I would propose:
if isinstance(ModelForm, ModelFormMetaclass): form = ModelForm(request.POST, request.FILES) else form = ModelForm
This way gives the flexibility to override the function get_form(self, request, obj=None, **kwargs), which could return a modelform_factory(self.model, **defaults) or an instance of a model form.
Change History (6)
by , 17 years ago
| Attachment: | T10305.diff added |
|---|
comment:1 by , 17 years ago
| Triage Stage: | Unreviewed → Design decision needed |
|---|
comment:3 by , 16 years ago
| Summary: | contrib/admin/options.py add_view, change_view → change the way ModelForms are instantiated in add_view, change_view |
|---|
Changed the summary to be more informative.
comment:4 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → New feature |
comment:5 by , 14 years ago
| Description: | modified (diff) |
|---|---|
| Easy pickings: | unset |
Reformatted description to be more readable.
Note:
See TracTickets
for help on using tickets.
My inclination is that this is the wrong way to go about doing this, an "instiate_form" hook or somethign similar is a much better API design IMO.