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)
Change History (5)
comment:1 by , 17 years ago
Keywords: | feature_request added |
---|
comment:2 by , 17 years ago
Keywords: | qs-rf added |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 17 years ago
Attachment: | mult_update_partial.diff added |
---|
comment:3 by , 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.
need testing doing part1