I am creating a simple application with Django. I realized that I am doing the same kind of operations very often. For example I often need to get all Article objects which have isPublick = True. So I am wondering, is it possible to define a get_published function in the model?
If the model looks like this (simplified)
class Article(models.Model):
title = models.CharField(...)
isPublished = models.BooleandField()
def get_active(self):
return Article.objects.filter(isPublicshed = 1)
But this doesn't seem to work.
Can you suggest a way of implementing the function?