Django

Code

Ticket #3182 (new)

Opened 2 years ago

Last modified 10 months ago

model instance update() method and QuerySet update_or_create() method

Reported by: Gary Wilson <gary.wilson@gmail.com> Assigned to: nobody
Milestone: Component: Database wrapper
Version: Keywords:
Cc: gary.wilson@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

Method would call get_or_create(), updating the object's data if the object already existed.

Idea came up in:

http://groups.google.com/group/django-developers/browse_thread/thread/49a6b99dbcea4364/

Attachments

update_or_create.diff (1.4 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 12/22/06 00:57:50.
update_or_create() methods for QuerySet? and Manager
update_or_create2.diff (7.0 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 12/24/06 16:49:14.
added documentation and tests
update_or_create3.diff (7.0 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 12/24/06 23:01:29.
removed the "required" wording in the documentation
update_and_update_or_create.diff (11.5 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 12/26/06 00:07:07.
update() from #3180 and update_or_create() together

Change History

12/22/06 00:57:25 changed by Gary Wilson <gary.wilson@gmail.com>

  • cc set to gary.wilson@gmail.com.
  • summary changed from update_or_create() QuerySet method to [patch] update_or_create() QuerySet method.

12/22/06 00:57:50 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment update_or_create.diff added.

update_or_create() methods for QuerySet? and Manager

12/22/06 01:05:22 changed by Gary Wilson <gary.wilson@gmail.com>

I should note that this patch depends on the update() method in #3181.

12/24/06 16:49:14 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment update_or_create2.diff added.

added documentation and tests

12/24/06 23:01:29 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment update_or_create3.diff added.

removed the "required" wording in the documentation

12/24/06 23:16:58 changed by Gary Wilson <gary.wilson@gmail.com>

Correction: I should note that this patch depends on the update() method in #3180.

12/26/06 00:07:07 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment update_and_update_or_create.diff added.

update() from #3180 and update_or_create() together

01/06/07 10:02:22 changed by anonymous

  • priority changed from normal to highest.

01/14/07 20:47:51 changed by Gary Wilson <gary.wilson@gmail.com>

  • priority changed from highest to normal.
  • summary changed from [patch] update_or_create() QuerySet method to [patch] model instance update() method and QuerySet update_or_create() method.

Changed the title to reflect the merging of the two patches.

01/17/07 20:37:21 changed by Gary Wilson <gary.wilson@gmail.com>

  • summary changed from [patch] model instance update() method and QuerySet update_or_create() method to model instance update() method and QuerySet update_or_create() method.
  • stage changed from Unreviewed to Ready for checkin.

As per Jacob's comments in the mailing list.

09/10/07 22:07:52 changed by gwilson

  • needs_better_patch set to 1.
  • stage changed from Ready for checkin to Accepted.

Model instance update method should not use __dict__.update() as that won't work with fields like ForeignKey. Perhaps we need to loop through all the fields, using setattr and the other logic present in Model.__init__().


Add/Change #3182 (model instance update() method and QuerySet update_or_create() method)




Change Properties
Action