MCPcopy
hub / github.com/django/django / delete

Method delete

django/db/models/query.py:1310–1338  ·  view source on GitHub ↗

Delete the records in the current QuerySet.

(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

_chainMethod · 0.95
collectMethod · 0.95
deleteMethod · 0.95
CollectorClass · 0.90
clear_orderingMethod · 0.80

Tested by

no test coverage detected