Opened 18 years ago

Closed 18 years ago

#3180 closed enhancement (duplicate)

[patch] update() method for model instances

Reported by: Gary Wilson <gary.wilson@…> Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: gary.wilson@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Updating objects

The create(**kwargs) method is a convenience method for updating and saving an object all in one step. If we were to get an object:

p = Person.objects.get(pk=1)

Then, we could update the person's first and last name like so:

p.update(first_name="Bruce", last_name="Springsteen")

Note that this would be equivalent to the following:

p.first_name = "Bruce"
p.last_name = "Springsteen"
p.save()

The idea came from this discussion:

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

Attachments (2)

update.diff (3.9 KB ) - added by Gary Wilson <gary.wilson@…> 18 years ago.
update() method with documentation and tests
update2.diff (4.7 KB ) - added by Gary Wilson <gary.wilson@…> 18 years ago.
documentation integrated into the "Saving changes to objects" section instead of creating a new section

Download all attachments as: .zip

Change History (5)

by Gary Wilson <gary.wilson@…>, 18 years ago

Attachment: update.diff added

update() method with documentation and tests

comment:1 by Gary Wilson <gary.wilson@…>, 18 years ago

Cc: gary.wilson@… added

comment:2 by Gary Wilson <gary.wilson@…>, 18 years ago

Actually, the "Updating objects" section I added to the docs should probably be integrated into the "Saving changes to objects" section.

by Gary Wilson <gary.wilson@…>, 18 years ago

Attachment: update2.diff added

documentation integrated into the "Saving changes to objects" section instead of creating a new section

comment:3 by Jacob, 18 years ago

Resolution: duplicate
Status: newclosed

Superseded by #3182.

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