Django

Code

Ticket #8672 (closed: wontfix)

Opened 10 months ago

Last modified 4 months ago

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

Reported by: Richard Davies <richard.davies@elastichosts.com> Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: richard.davies@elastichosts.com Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

flags-for-modelform-save.diff (4.2 kB) - added by Richard Davies <richard.davies@elastichosts.com> on 08/29/08 05:04:53.
one-more.diff (4.8 kB) - added by Richard Davies <richard.davies@elastichosts.com> on 08/29/08 05:27:35.
Additional to previous patch

Change History

08/29/08 05:04:53 changed by Richard Davies <richard.davies@elastichosts.com>

  • attachment flags-for-modelform-save.diff added.

08/29/08 05:27:35 changed by Richard Davies <richard.davies@elastichosts.com>

  • attachment one-more.diff added.

Additional to previous patch

08/29/08 05:31:57 changed by Richard Davies <richard.davies@elastichosts.com>

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_docs changed.
  • needs_tests changed.
  • milestone set to 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.

08/29/08 05:36:06 changed by Richard Davies <richard.davies@elastichosts.com>

  • component changed from Forms to Database wrapper.

08/29/08 09:29:33 changed by Alex

  • stage changed from Unreviewed to Design decision needed.

08/29/08 11:58:24 changed by mtredinnick

  • milestone changed from 1.0 to post-1.0.

11/03/08 10:44:56 changed by dc

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)

12/01/08 22:07:43 changed by mtredinnick

(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.

12/01/08 22:09:56 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to wontfix.

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.

12/02/08 00:00:44 changed by mtredinnick

(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.

02/25/09 13:51:44 changed by

  • milestone deleted.

Milestone post-1.0 deleted


Add/Change #8672 (ModelForm.save() should implement force_insert and force_update, like Model.save())




Change Properties
Action