Django models, custom functions

Viewed 44186

I am creating simple application with django. Also, I realized that I am doing some kind of operations very often. For example I often need to get all Article objects which have isPublick = True. So I am thinking is that possible to define get_published function in model?

if models 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 it doesn't work this way

Can you suggest a way of implementing the function?

3 Answers
Related