Ticket #9885: query.diff

File query.diff, 1.6 KB (added by matehat, 6 years ago)
  • django/db/models/query.py

     
    379379        """
    380380        Deletes the records in the current QuerySet.
    381381        """
     382        from django.db.models import signals
     383       
    382384        assert self.query.can_filter(), \
    383385                "Cannot use 'limit' or 'offset' with delete."
    384 
     386       
     387        signals.pre_batch_delete.send(sender=self.model, queryset=self)
    385388        del_query = self._clone()
    386389
    387390        # Disable non-supported fields.
     
    403406
    404407        # Clear the result cache, in case this QuerySet gets reused.
    405408        self._result_cache = None
     409        signals.post_batch_delete.send(sender=self.model, queryset=self)
     410       
    406411    delete.alters_data = True
    407412
    408413    def update(self, **kwargs):
     
    410415        Updates all elements in the current QuerySet, setting all the given
    411416        fields to the appropriate values.
    412417        """
     418        from django.db.models import signals
     419       
    413420        assert self.query.can_filter(), \
    414421                "Cannot update a query once a slice has been taken."
     422        signals.pre_batch_update.send(sender=self.model, queryset=self, raw=kwargs)
    415423        query = self.query.clone(sql.UpdateQuery)
    416424        query.add_update_values(kwargs)
    417425        rows = query.execute_sql(None)
     426        signals.post_batch_update.send(sender=self.model, queryset=self, raw=kwargs)
    418427        transaction.commit_unless_managed()
    419428        self._result_cache = None
    420429        return rows
Back to Top