Opened 7 years ago

Last modified 2 years ago

#10305 new New feature

change the way ModelForms are instantiated in add_view, change_view

Reported by: ctao Owned by: nobody
Component: contrib.admin Version: master
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 julien)

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.

Attachments (1)

T10305.diff (4.5 KB) - added by ctao 7 years ago.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by ctao

comment:1 Changed 7 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

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.

comment:2 Changed 7 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:3 Changed 5 years ago by rctay

  • Summary changed from contrib/admin/options.py add_view, change_view to change the way ModelForms are instantiated in add_view, change_view

Changed the summary to be more informative.

comment:4 Changed 4 years ago by SmileyChris

  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 4 years ago by julien

  • Description modified (diff)
  • Easy pickings unset

Reformatted description to be more readable.

comment:6 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 Changed 2 years ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

I agree with Alex: the proposed API is clumsy. But the need is real, so moving this to accepted. Determine a better API first though.

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