[Fixed]-Adding annotations to all querysets with a custom QuerySet as Manager


You should use the from_queryset method – it allows you to create a Manager class which you can further customise before applying to your model. For example:

class CustomQuerySet(models.QuerySet):
    def most_liked(self):
        return self.filter(...)

class CustomManager(models.Manager.from_queryset(CustomQuerySet)):
    def get_queryset(self):
        return super(CustomManager, self).get_queryset() \

class Model(models.Model):
    objects = CustomManager()

Leave a comment