15👍
✅
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() \
.annotate(...)
class Model(models.Model):
objects = CustomManager()
👤Greg
Source:stackexchange.com