Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#9284 closed (fixed)

BaseModelFormSet and BaseInlineFormSet should call ModelForm.save() 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: no UI/UX: no

Description (last modified by jkocherhans)

The most current code is at http://github.com/jkocherhans/django/tree/formset-updates

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 16 years ago.
Fixed a typo

Download all attachments as: .zip

Change History (5)

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: newclosed

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 by jkocherhans, 16 years ago

Description: modified (diff)
Has patch: set
Resolution: invalid
Status: closedreopened
Summary: Formsets don't call form's saveBaseModelFormSet and BaseInlineFormSet should call ModelForm.save() when saving objects
Triage Stage: UnreviewedDesign decision needed

by jkocherhans, 16 years ago

Attachment: 9284.diff added

Fixed a typo

comment:3 by jkocherhans, 16 years ago

Resolution: fixed
Status: reopenedclosed

(In [10190]) Fixed #9284. Fixed #8813. BaseModelFormSet now calls ModelForm.save().
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 by jashugan, 16 years ago

This looks excellent. Thanks!

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