Opened 19 years ago

Closed 18 years ago

Last modified 17 years ago

#436 closed defect (fixed)

Create an API to update and delete multiple objects in a single call

Reported by: Maurycy Pawłowski-Wieroński <maurycypw@…> 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 Maurycy Pawłowski-Wieroński <maurycypw@…>, 19 years ago

Type: defectenhancement

comment:2 by Adrian Holovaty, 19 years ago

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?

comment:3 by cpr@…, 19 years ago

Why not use allow delete_list as in:

choices.delete_list(poll__exact=1)

comment:4 by Maurycy Pawłowski-Wieroński <maurycypw@…>, 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 Adrian Holovaty, 19 years ago

Summary: Fetch parameter to get_list and get_object, which would point whether select objectsCreate 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:6 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

We've got bulk delete now.

comment:7 by Link, 18 years ago

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