MCPcopy
hub / github.com/django/django / delete_batch

Method delete_batch

django/db/models/sql/subqueries.py:27–46  ·  view source on GitHub ↗

Set up and execute delete queries for all the objects in pk_list. More than one physical query may be executed if there are a lot of values in pk_list.

(self, pk_list, using)

Source from the content-addressed store, hash-verified

25 return self.get_compiler(using).execute_sql(ROW_COUNT)
26
27 def delete_batch(self, pk_list, using):
28 """
29 Set up and execute delete queries for all the objects in pk_list.
30
31 More than one physical query may be executed if there are a
32 lot of values in pk_list.
33 """
34 # number of objects deleted
35 num_deleted = 0
36 field = self.get_meta().pk
37 for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
38 self.clear_where()
39 self.add_filter(
40 f"{field.attname}__in",
41 pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE],
42 )
43 num_deleted += self.do_query(
44 self.get_meta().db_table, self.where, using=using
45 )
46 return num_deleted
47
48
49class UpdateQuery(Query):

Callers 1

deleteMethod · 0.95

Calls 4

do_queryMethod · 0.95
clear_whereMethod · 0.80
add_filterMethod · 0.80
get_metaMethod · 0.45

Tested by

no test coverage detected