Code

Opened 7 years ago

Closed 7 years ago

#3180 closed enhancement (duplicate)

[patch] update() method for model instances

Reported by: Gary Wilson <gary.wilson@…> Owned by: adrian
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: UI/UX:

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@…> 7 years ago.
update() method with documentation and tests
update2.diff (4.7 KB) - added by Gary Wilson <gary.wilson@…> 7 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)

Changed 7 years ago by Gary Wilson <gary.wilson@…>

update() method with documentation and tests

comment:1 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Cc gary.wilson@… added

comment:2 Changed 7 years ago by Gary Wilson <gary.wilson@…>

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

Changed 7 years ago by Gary Wilson <gary.wilson@…>

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

comment:3 Changed 7 years ago by jacob

  • Resolution set to duplicate
  • Status changed from new to closed

Superseded by #3182.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.