Changes between Initial Version and Version 5 of Ticket #10305
- Timestamp:
- May 13, 2011, 8:54:35 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #10305
- Property Triage Stage Unreviewed → Design decision needed
- Property Milestone post-1.0
- Property Summary contrib/admin/options.py add_view, change_view → change the way ModelForms are instantiated in add_view, change_view
- Property Severity → Normal
- Property Type → New feature
- Property Easy pickings unset
-
Ticket #10305 – Description
initial v5 1 add_view, change_view hasthe following code:1 `add_view` and `change_view` have the following code: 2 2 3 {{{#!python 3 4 ModelForm = self.get_form(request) 4 5 ... 6 form = ModelForm(request.POST, request.FILES) 7 }}} 5 8 6 form = ModelForm(request.POST, request.FILES) 7 or 9 or: 10 {{{#!python 8 11 form = ModelForm(initial=initial) 9 or 12 }}} 13 14 or: 15 {{{#!python 10 16 form = ModelForm(request.POST, request.FILES, instance=obj) 17 }}} 11 18 12 19 I would propose: 13 20 {{{#!python 14 21 if isinstance(ModelForm, ModelFormMetaclass): 15 22 form = ModelForm(request.POST, request.FILES) 16 23 else 17 24 form = ModelForm 25 }}} 18 26 19 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.27 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.