Opened 18 years ago
Closed 18 years ago
#3180 closed enhancement (duplicate)
[patch] update() method for model instances
Reported by: | 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)
Change History (5)
by , 18 years ago
Attachment: | update.diff added |
---|
comment:1 by , 18 years ago
Cc: | added |
---|
comment:2 by , 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 , 18 years ago
Attachment: | update2.diff added |
---|
documentation integrated into the "Saving changes to objects" section instead of creating a new section
update() method with documentation and tests