Django

Code

Ticket #3180 (closed: duplicate)

Opened 2 years ago

Last modified 2 years ago

[patch] update() method for model instances

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

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

update.diff (3.9 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 12/21/06 23:50:46.
update() method with documentation and tests
update2.diff (4.7 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 12/26/06 00:00:51.
documentation integrated into the "Saving changes to objects" section instead of creating a new section

Change History

12/21/06 23:50:46 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment update.diff added.

update() method with documentation and tests

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

  • cc set to gary.wilson@gmail.com.

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

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

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

  • attachment update2.diff added.

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

12/26/06 08:26:59 changed by jacob

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

Superseded by #3182.


Add/Change #3180 ([patch] update() method for model instances)




Change Properties
Action