Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#14574 closed New feature (fixed)

Initial values support for inline model formsets

Reported by: Simon Litchfield Owned by: nobody
Component: Forms Version: master
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 6 years ago.
14574.diff (2.0 KB) - added by Claude Paroz 5 years ago.
Initial values for model formsets
14574-2.diff (5.7 KB) - added by Claude Paroz 5 years ago.
patch including tests
14574-3.diff (5.6 KB) - added by Claude Paroz 5 years ago.
Remove unnecessary KeyError catching

Download all attachments as: .zip

Change History (16)

Changed 6 years ago by Simon Litchfield

Attachment: inlineformset-kwargs.diff added

comment:1 Changed 6 years ago by Simon Litchfield

Cc: Honza Král added
Has patch: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 6 years ago by Simon Litchfield

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 Changed 6 years ago by Simon Litchfield

milestone: 2.0

comment:4 Changed 6 years ago by Paul Oswald

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 Changed 5 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:6 Changed 5 years ago by Ramiro Morales

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 Changed 5 years ago by Jannis Leidel

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

Changed 5 years ago by Claude Paroz

Attachment: 14574.diff added

Initial values for model formsets

comment:8 Changed 5 years ago by Claude Paroz

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.

Changed 5 years ago by Claude Paroz

Attachment: 14574-2.diff added

patch including tests

comment:9 Changed 5 years ago by Claude Paroz

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).

Changed 5 years ago by Claude Paroz

Attachment: 14574-3.diff added

Remove unnecessary KeyError catching

comment:10 Changed 5 years ago by Claude Paroz

Cc: claude@… added

comment:11 Changed 5 years ago by Ramiro Morales

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 Changed 5 years ago by Evstifeev Roman

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

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