273 | | # Delete objects in chunks to prevent the list of related objects from |
274 | | # becoming too long. |
275 | | while 1: |
276 | | # Collect all the objects to be deleted in this chunk, and all the |
277 | | # objects that are related to the objects that are to be deleted. |
278 | | seen_objs = SortedDict() |
279 | | for object in del_query[:CHUNK_SIZE]: |
280 | | object._collect_sub_objects(seen_objs) |
281 | | |
282 | | if not seen_objs: |
283 | | break |
284 | | delete_objects(seen_objs) |
285 | | |
| 270 | # Delete objects individually if self is sliced or self.model has a custom delete() method. |
| 271 | # Use a DELETE query otherwise. |
| 272 | # See ticket #6915. |
| 273 | from django.db.models import Model |
| 274 | if not self.query.can_filter() or self.model is not None and self.model.delete != Model.delete: |
| 275 | for obj in del_query: |
| 276 | obj.delete() |
| 277 | |
| 278 | else: |
| 279 | # Delete objects in chunks to prevent the list of related objects from |
| 280 | # becoming too long. |
| 281 | while 1: |
| 282 | # Collect all the objects to be deleted in this chunk, and all the |
| 283 | # objects that are related to the objects that are to be deleted. |
| 284 | seen_objs = SortedDict() |
| 285 | for object in del_query[:CHUNK_SIZE]: |
| 286 | object._collect_sub_objects(seen_objs) |
| 287 | |
| 288 | if not seen_objs: |
| 289 | break |
| 290 | delete_objects(seen_objs) |
| 291 | |