Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#9284 closed (fixed)

BaseModelFormSet and BaseInlineFormSet should call when saving objects

Reported by: drozzy@… Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by jkocherhans)

The most current code is at

This introduces some backwards incompatibilities for people who overrode either type of formset's __init__ method, but this is how I would have written the model formset code if we'd actually had modelforms first. This doesn't really solve any specific problems that I know of.

Attachments (1)

9284.diff (16.7 KB) - added by jkocherhans 7 years ago.
Fixed a typo

Download all attachments as: .zip

Change History (5)

comment:1 Changed 8 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Child forms don't always have enough information to save themselves in the situation when you're adding related elements to some other model: the related elements need to know which related model id to use, for example. If you look at the logic in model formsets (and you're only talking about model formsets here, since normal formsets don't have a save() method), you'll see that there's quite a bit of interaction between information that exists only on the formset object and the forms itself.

If you can come up with some patch that works in all cases and is obviously neater than the current code, then reopen the ticket, but this is currently a bit too ill-defined to be a ticket we can resolve.

comment:2 Changed 7 years ago by jkocherhans

  • Description modified (diff)
  • Has patch set
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Summary changed from Formsets don't call form's save to BaseModelFormSet and BaseInlineFormSet should call when saving objects
  • Triage Stage changed from Unreviewed to Design decision needed

Changed 7 years ago by jkocherhans

Fixed a typo

comment:3 Changed 7 years ago by jkocherhans

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

(In [10190]) Fixed #9284. Fixed #8813. BaseModelFormSet now calls
This is backwards-incompatible if you were doing things to 'initial' in BaseModelFormSet.init, or if you relied on the internal _total_form_count or _initial_form_count attributes of BaseFormSet. Those attributes are now public methods.

comment:4 Changed 7 years ago by jashugan

This looks excellent. Thanks!

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