18👍
Not without writing your own custom SQL or managers or something; they are apparently working on it though.
52👍
For those who are still looking for an efficient way to bulk delete in django, here’s a possible solution:
The reason delete()
may be so slow is twofold: 1) Django has to ensure cascade deleting functions properly, thus looking for foreign key references to your models; 2) Django has to handle pre and post-save signals for your models.
If you know your models don’t have cascade deleting or signals to be handled, you can accelerate this process by resorting to the private API _raw_delete
as follows:
queryset._raw_delete(queryset.db)
More details in here. Please note that Django already tries to make a good handling of these events, though using the raw delete is, in many situations, much more efficient.
- [Django]-Django Admin – Disable the 'Add' action for a specific model
- [Django]-Object has no attribute 'get'
- [Django]-How to concatenate strings in django templates?
14👍
Bulk delete is already part of django
Keep in mind that this will, whenever possible, be executed purely in SQL
- [Django]-How does Django's nested Meta class work?
- [Django]-Django modifying the request object
- [Django]-Django post_save() signal implementation