Code

Ticket #9885: query.diff

File query.diff, 1.6 KB (added by matehat, 5 years ago)
Line 
1Index: django/db/models/query.py
2===================================================================
3--- django/db/models/query.py   (revision 9660)
4+++ django/db/models/query.py   (working copy)
5@@ -379,9 +379,12 @@
6         """
7         Deletes the records in the current QuerySet.
8         """
9+        from django.db.models import signals
10+       
11         assert self.query.can_filter(), \
12                 "Cannot use 'limit' or 'offset' with delete."
13-
14+       
15+        signals.pre_batch_delete.send(sender=self.model, queryset=self)
16         del_query = self._clone()
17 
18         # Disable non-supported fields.
19@@ -403,6 +406,8 @@
20 
21         # Clear the result cache, in case this QuerySet gets reused.
22         self._result_cache = None
23+        signals.post_batch_delete.send(sender=self.model, queryset=self)
24+       
25     delete.alters_data = True
26 
27     def update(self, **kwargs):
28@@ -410,11 +415,15 @@
29         Updates all elements in the current QuerySet, setting all the given
30         fields to the appropriate values.
31         """
32+        from django.db.models import signals
33+       
34         assert self.query.can_filter(), \
35                 "Cannot update a query once a slice has been taken."
36+        signals.pre_batch_update.send(sender=self.model, queryset=self, raw=kwargs)
37         query = self.query.clone(sql.UpdateQuery)
38         query.add_update_values(kwargs)
39         rows = query.execute_sql(None)
40+        signals.post_batch_update.send(sender=self.model, queryset=self, raw=kwargs)
41         transaction.commit_unless_managed()
42         self._result_cache = None
43         return rows