Delete the records in the current QuerySet.
(self)
| 1308 | ) |
| 1309 | |
| 1310 | def delete(self): |
| 1311 | """Delete the records in the current QuerySet.""" |
| 1312 | self._not_support_combined_queries("delete") |
| 1313 | if self.query.is_sliced: |
| 1314 | raise TypeError("Cannot use 'limit' or 'offset' with delete().") |
| 1315 | if self.query.distinct_fields: |
| 1316 | raise TypeError("Cannot call delete() after .distinct(*fields).") |
| 1317 | if self._fields is not None: |
| 1318 | raise TypeError("Cannot call delete() after .values() or .values_list()") |
| 1319 | |
| 1320 | del_query = self._chain() |
| 1321 | |
| 1322 | # The delete is actually 2 queries - one to find related objects, |
| 1323 | # and one to delete. Make sure that the discovery of related |
| 1324 | # objects is performed on the same database as the deletion. |
| 1325 | del_query._for_write = True |
| 1326 | |
| 1327 | # Disable non-supported fields. |
| 1328 | del_query.query.select_for_update = False |
| 1329 | del_query.query.select_related = False |
| 1330 | del_query.query.clear_ordering(force=True) |
| 1331 | |
| 1332 | collector = Collector(using=del_query.db, origin=self) |
| 1333 | collector.collect(del_query) |
| 1334 | num_deleted, num_deleted_per_model = collector.delete() |
| 1335 | |
| 1336 | # Clear the result cache, in case this QuerySet gets reused. |
| 1337 | self._result_cache = None |
| 1338 | return num_deleted, num_deleted_per_model |
| 1339 | |
| 1340 | delete.alters_data = True |
| 1341 | delete.queryset_only = True |
nothing calls this directly
no test coverage detected