Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#14574 closed New feature (fixed)

Initial values support for inline model formsets

Reported by: simon29 Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: inlineformset_factory BaseInlineFormSet BaseModelFormSet
Cc: Honza_Kral, 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 simon29 5 years ago.
14574.diff (2.0 KB) - added by claudep 4 years ago.
Initial values for model formsets
14574-2.diff (5.7 KB) - added by claudep 4 years ago.
patch including tests
14574-3.diff (5.6 KB) - added by claudep 3 years ago.
Remove unnecessary KeyError catching

Download all attachments as: .zip

Change History (16)

Changed 5 years ago by simon29

comment:1 Changed 5 years ago by simon29

  • Cc Honza_Kral added
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by simon29

  • Has patch unset
  • Keywords BaseInlineFormSet BaseModelFormSet added; BaseInlineModelFormSet removed
  • milestone changed from 1.3 to 2.0
  • Summary changed from Missing kwargs from inline formsets breaks initial support to Initial values support for model formsets
  • Triage Stage changed from Unreviewed to Design 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 5 years ago by simon29

  • milestone 2.0 deleted

comment:4 Changed 5 years ago by poswald

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 4 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:6 Changed 4 years ago by ramiro

  • Easy pickings unset
  • Summary changed from Initial values support for model formsets to Initial values support for inline model formsets
  • UI/UX unset

#16446 reported a manifestation of this in FormWizard

comment:7 Changed 4 years ago by jezdez

  • Has patch set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Design decision needed to Accepted

Changed 4 years ago by claudep

Initial values for model formsets

comment:8 Changed 4 years ago by claudep

  • 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 4 years ago by claudep

patch including tests

comment:9 Changed 4 years ago by claudep

  • 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 3 years ago by claudep

Remove unnecessary KeyError catching

comment:10 Changed 3 years ago by claudep

  • Cc claude@… added

comment:11 Changed 3 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by Fak3

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

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