How can I override the update() method of a django model inside a custom manager?
I would like to modify the behavior of some methods(all(), update(), filter()) of a django model and I have tried to override using what my code down here suggests but nothing is happening. I have tried using QuerySet instead of inheriting from Manager but I am failing to override it properly as I am getting empty results all over the system.
class undeletedObjectManager(models.Manager):
def get_queryset(self):
return super(undeletedObjectManager, self).get_queryset().filter(deleted=False)
def update(self, *args, **kwargs):
if "deleted" in args:
# some logic here
super().update(*args, **kwargs)
class Transaction(models.Model):
author = models.ForeignKey(Branch, null=True)
objects = undeletedObjectManager()
def __str__(self):
return 'Tr. by {}'.format(self.author.name)
the update() method isn't reached and I am guessing it is because I am not overriding the correct member. Is there a specific method name? in both Manager and QuerySet classes? How should I override them?