Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#1219 closed defect (fixed)

There's no way to bulk delete a set of objects

Reported by: jacobkm Owned by: Russell Keith-Magee
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Ned Batchelder wrote to django-users:

> I'm used to writing SQL statements like:
> 
>    delete from app_things where type = 'foo';
> 
> to delete a number of objects at once.  I don't see a way to do this
> type of delete in Django. I was hoping for something like:
> 
>    things.delete(type__exact='foo')
> 
> Certainly I could do this:
> 
>    for t in things.get_list(type__exact='foo'):
>       t.delete()
> 
> but this incurs a lot more database activity.

Attachments (2)

bulk-delete.patch (19.4 KB) - added by Russell Keith-Magee 11 years ago.
Patch implementing bulk delete in post-descriptor magic-removal
bulk-delete-v2.patch (20.0 KB) - added by Russell Keith-Magee 11 years ago.
Patch implementing bulk delete in post-descriptor magic-removal

Download all attachments as: .zip

Change History (10)

comment:1 Changed 11 years ago by Russell Keith-Magee

Here's a patch against magic-removal that adds bulk delete to the Manager for a model class. Is this approach going to get obsoleted by the descriptor work?

comment:2 Changed 11 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [2029]) magic-removal: Fixed #1219 - Added bulk delete for objects.

comment:3 Changed 11 years ago by Russell Keith-Magee

(In [2048]) magic-removal: Refs #1219 -- added documentation for bulk delete feature.

comment:4 Changed 11 years ago by hugo

Reporter: changed from Jacob to russelm
Resolution: fixed
Status: closedreopened

I reopen this ticket because of the different behaviour of bulk delete and object delete with regard to related objects and relation tables for ManyToMany. See this discussion in django-users.

comment:5 Changed 11 years ago by hugo

Owner: changed from Adrian Holovaty to russelm
Reporter: changed from russelm to jacobkm
Status: reopenednew

comment:6 Changed 11 years ago by Russell Keith-Magee

Owner: changed from russelm to Russell Keith-Magee

Changed 11 years ago by Russell Keith-Magee

Attachment: bulk-delete.patch added

Patch implementing bulk delete in post-descriptor magic-removal

Changed 11 years ago by Russell Keith-Magee

Attachment: bulk-delete-v2.patch added

Patch implementing bulk delete in post-descriptor magic-removal

comment:7 Changed 11 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [2307]) magic-removal: Fixed #1219 -- Added implementation of bulk delete, and factored common deletion code out of individual models.

comment:8 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

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