#436 closed defect (fixed)
Create an API to update and delete multiple objects in a single call
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Metasystem | Version: | |
Severity: | normal | Keywords: | |
Cc: | wojtek@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Many times you need to delete or update one or many objects, without retreving them first.
My proposal is to add fetch parameter to get_list and get_object methods, which would point whether send select query or create empty models with only specified fields, for further operations, like delete or update.
For example:
# No SQL queries, since fetch=False is set. choices are empty and have only poll_id field. choices = choices.get_list(poll__exact=1, fetch=False) # Now call: DELETE FROM poll_choices WHERE poll_id = 1 choices.delete()
See also #433.
Change History (7)
comment:1 by , 19 years ago
Type: | defect → enhancement |
---|
comment:2 by , 19 years ago
comment:4 by , 19 years ago
I'm trying to delete one or many objects, without need to select them first.
Also, I think that delete_list is wrong. One, it'll mislead if you'd like to remove only one object. Two, my syntax also makes it possible to update one or many objects, without fetching them:
# No SQL queries, since fetch=False is set. choices are empty and have only poll_id field. choices = choices.get_list(poll__exact=1, fetch=False) # Set ''votes'' to zero, in these ghost objects. choices.votes = 0 # Save them calling: UPDATE SET votes = 0 WHERE poll_choices.poll_id = 1 choices.save()
comment:5 by , 19 years ago
Summary: | Fetch parameter to get_list and get_object, which would point whether select objects → Create an API to update and delete multiple objects in a single call |
---|
That's very intriguing, but the syntax is a bit unclear. Dealing with "ghost objects" is bound to give people headaches. Let's come up with another solution to "UPDATE SET votes = 0 WHERE poll_choices.poll_id = 1"
.
comment:7 by , 18 years ago
Type: | enhancement → defect |
---|
I don't understand what you're trying to do here. Could you give some more code examples and more explanation of what problem this solves?