Last Updated: July 02, 2017
·
7.647K
· marconi

Django: sending update signal

from django.dispatch import Signal

post_update = Signal()

class MyCustomQuerySet(models.query.QuerySet):
def update(self, kwargs):
super(MyCustomQuerySet, self).update(
kwargs)
post_update.send(sender=self.model)

class MyCustomManager(models.Manager):
def getqueryset(self):
return MyCustomQuerySet(self.model, using=self._db)

then you can declare your models like:

class MyCustomModel(models.Model):
objects = MyCustomManager()

now whenever you call MyCustomModel.objects.update(...) it'll trigger the post_update signal.