Opened 17 years ago

Closed 17 years ago

#5417 closed (duplicate)

Add a way to update multiple records at once

Reported by: Adrian Holovaty Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: feature_request, qs-rf
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Django ORM currently doesn't allow for the update of multiple records in a single statement. We can add this feature in a pretty clean and consistent way by adding a QuerySet.update() method:

# UPDATE place SET city='Chicago' WHERE city='chicago';
Place.objects.filter(city='chicago').update(city='Chicago')

# UPDATE contestant SET age=age+2 WHERE answer='1';
Contestant.objects.filter(answer='1').update(age=SqlClause('age+2'))

The second example introduces SqlClause, which would be a way of specifying clauses instead of hard-coded values. We could potentially begin using this SqlClause in other places, too.

Attachments (1)

mult_update_partial.diff (1.0 KB ) - added by deepak <deep.thukral@…> 17 years ago.
need testing doing part1

Download all attachments as: .zip

Change History (5)

comment:1 by Philippe Raoult, 17 years ago

Keywords: feature_request added

comment:2 by Simon G. <dev@…>, 17 years ago

Keywords: qs-rf added
Triage Stage: UnreviewedAccepted

by deepak <deep.thukral@…>, 17 years ago

Attachment: mult_update_partial.diff added

need testing doing part1

comment:3 by deepak <deep.thukral@…>, 17 years ago

Has patch: set
Needs tests: set

Sorry, I was working on it before qs-rf tag, so I just added where i was till then. Its partial patch(covers example 1) and needs testing.

comment:4 by James Bennett, 17 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #4260.

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