Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#8672 closed (wontfix)

ModelForm.save() should implement force_insert and force_update, like Model.save()

Reported by: Richard Davies <richard.davies@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: richard.davies@… 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

[8267] added the ability to force an SQL insert (or force an update) via a model's save() method.

The same force_insert and force_update flags should be supported in a modelform's save() method.

These flags enable better control over some edge cases - e.g. force_insert will prevent overwriting existing data if the same primary key has accidentally been specified.

Attachments (2)

flags-for-modelform-save.diff (4.2 KB ) - added by Richard Davies <richard.davies@…> 16 years ago.
one-more.diff (4.8 KB ) - added by Richard Davies <richard.davies@…> 16 years ago.
Additional to previous patch

Download all attachments as: .zip

Change History (11)

by Richard Davies <richard.davies@…>, 16 years ago

by Richard Davies <richard.davies@…>, 16 years ago

Attachment: one-more.diff added

Additional to previous patch

comment:1 by Richard Davies <richard.davies@…>, 16 years ago

Has patch: set
milestone: 1.0

The patch one-more.diff is the most recent, and contains all required changes.

I notice that the two helper functions make_model_save and make_instance_save are not used anywhere in Django, so are probably legacy which could be removed. I haven't done this here - just patched them along with the rest.

comment:2 by Richard Davies <richard.davies@…>, 16 years ago

Component: FormsDatabase wrapper

comment:3 by Alex Gaynor, 16 years ago

Triage Stage: UnreviewedDesign decision needed

comment:4 by Malcolm Tredinnick, 16 years ago

milestone: 1.0post-1.0

comment:5 by dc, 15 years ago

After this patch ModelForm.save() signature will be different from Form.save(). Is this ok?
Desired effect can already be achieved with

model = model_form.save(commit=False)
model.save(force_insert=True)

comment:6 by Malcolm Tredinnick, 15 years ago

(In [9539]) Added a short note to the modelforms documentation linking between
save(commit=False) and using force_insert or force_update on the Model.save()
call. Refs #8672.

comment:7 by Malcolm Tredinnick, 15 years ago

Resolution: wontfix
Status: newclosed

The consensus amongst the maintainers is that complicating the API a bit by adding two extra parameters isn't worth it in this case. I've added a note to the documentation to remind people about commit=False in these circumstances.

comment:8 by Malcolm Tredinnick, 15 years ago

(In [9541]) [1.0.X] Added a short note to the modelforms documentation linking between
save(commit=False) and using force_insert or force_update on the Model.save()
call. Refs #8672.

Backport of r9539 from trunk.

comment:9 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

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