Opened 10 years ago

Closed 9 years ago

Last modified 8 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
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: UI/UX:

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 Changed 10 years ago by Maurycy Pawłowski-Wieroński <maurycypw@…>

  • Type changed from defect to enhancement

comment:2 Changed 10 years ago by adrian

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 Changed 10 years ago by cpr@…

Why not use allow delete_list as in:

choices.delete_list(poll__exact=1)

comment:4 Changed 10 years ago by Maurycy Pawłowski-Wieroński <maurycypw@…>

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 Changed 9 years ago by adrian

  • Summary changed from Fetch parameter to get_list and get_object, which would point whether select objects to 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:6 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

We've got bulk delete now.

comment:7 Changed 9 years ago by Link

  • Type changed from enhancement to defect
Note: See TracTickets for help on using tickets.
Back to Top