Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#14574 closed New feature (fixed)

Initial values support for inline model formsets

Reported by: Simon Litchfield Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords: inlineformset_factory BaseInlineFormSet BaseModelFormSet
Cc: Honza Král, claude@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ModelFormSet allows the initial={} parameter, but InlineModelFormSet doesn't; simply because it's missing kwargs. Patch attached.

Attachments (4)

inlineformset-kwargs.diff (1.0 KB ) - added by Simon Litchfield 14 years ago.
14574.diff (2.0 KB ) - added by Claude Paroz 13 years ago.
Initial values for model formsets
14574-2.diff (5.7 KB ) - added by Claude Paroz 13 years ago.
patch including tests
14574-3.diff (5.6 KB ) - added by Claude Paroz 13 years ago.
Remove unnecessary KeyError catching

Download all attachments as: .zip

Change History (16)

by Simon Litchfield, 14 years ago

Attachment: inlineformset-kwargs.diff added

comment:1 by Simon Litchfield, 14 years ago

Cc: Honza Král added
Has patch: set

comment:2 by Simon Litchfield, 14 years ago

Has patch: unset
Keywords: BaseInlineFormSet BaseModelFormSet added; BaseInlineModelFormSet removed
milestone: 1.32.0
Summary: Missing kwargs from inline formsets breaks initial supportInitial values support for model formsets
Triage Stage: UnreviewedDesign decision needed

Sorry, broken patch. Using initial on ModelFormSet overrides queryset populated values.

If anyone else is interested in adding initial= support for *ModelFormSets, I'll happily patch. I'd expect the initial values to populate the extra (empty) forms only. If it's a single dictionary, repeat it on all extra forms; if it's multiple then apply in order.

comment:3 by Simon Litchfield, 14 years ago

milestone: 2.0

comment:4 by Paul Oswald, 14 years ago

I just ran into this today. I expected to be able to pass initial values into a BaseInlineFormSet that I got from an inlineformset_factory. It is useful for setting default values on unbound forms.

Also similar to #12213

comment:5 by Julien Phalip, 13 years ago

Severity: Normal
Type: New feature

comment:6 by Ramiro Morales, 13 years ago

Easy pickings: unset
Summary: Initial values support for model formsetsInitial values support for inline model formsets
UI/UX: unset

#16446 reported a manifestation of this in FormWizard

comment:7 by Jannis Leidel, 13 years ago

Has patch: set
Needs tests: set
Patch needs improvement: set
Triage Stage: Design decision neededAccepted

by Claude Paroz, 13 years ago

Attachment: 14574.diff added

Initial values for model formsets

comment:8 by Claude Paroz, 13 years ago

Patch needs improvement: unset

I attached a starting point for supporting initial values for model formsets. If this approach and implementation is accepted, I might then work on tests and maybe adding an example to the doc.

by Claude Paroz, 13 years ago

Attachment: 14574-2.diff added

patch including tests

comment:9 by Claude Paroz, 13 years ago

Needs tests: unset

This second patch is more elaborate, as it includes tests and also adds support for inline model formsets (taken from initial patch).

by Claude Paroz, 13 years ago

Attachment: 14574-3.diff added

Remove unnecessary KeyError catching

comment:10 by Claude Paroz, 13 years ago

Cc: claude@… added

comment:11 by Ramiro Morales, 13 years ago

Resolution: fixed
Status: newclosed

In [17373]:

Added support for specifying initial values to model formsets and inline formsets.

This make them consistent with the similar capability of regular
formsets. Thanks to simon29 form the report and to Claude Paroz for the
patch.

Fixes #14574.

comment:12 by Evstifeev Roman, 13 years ago

I added ticket #17927, that is request for the same functionality for BaseGenericInlineFormSet

Last edited 13 years ago by Evstifeev Roman (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top