#8672 closed (wontfix)
ModelForm.save() should implement force_insert and force_update, like Model.save()
Reported by: | 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)
Change History (11)
by , 16 years ago
Attachment: | flags-for-modelform-save.diff added |
---|
by , 16 years ago
Attachment: | one-more.diff added |
---|
comment:1 by , 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 , 16 years ago
Component: | Forms → Database wrapper |
---|
comment:3 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:4 by , 16 years ago
milestone: | 1.0 → post-1.0 |
---|
comment:5 by , 16 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 , 16 years ago
comment:7 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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.
Additional to previous patch