Django add common conditions in model
<p>I have model </p>

<pre><code>class QuerySetManager(models.Manager):
    def get_query_set(self):
        return self.model.QuerySet(self.model)

class Post(models.Model):
    objects = QuerySetManager()
    STATUS = (
         (1, 'PENDING'),
         (2, 'ACTIVE'),
    )
    title = models.CharField(max_length=512,blank=False,null=True)
    status = models.IntegerField(default=1,choices=STATUS)
    class QuerySet(models.query.QuerySet):
        def active(self):
            return self.filter(status=2)
</code></pre>

<p>When I try to access this way</p>

<pre><code>Post.objects.active().filter(other_condition='xxx').all()
</code></pre>

<p>it throws error <code>'QuerySetManager' object has no attribute 'active'</code></p>

<p>Can anyone help me to achieve this?</p>

<p>I can't understand what you're doing here at all. The way to get a manager to return a queryset with the same methods is to use the <a href="https://docs.djangoproject.com/en/1.10/topics/db/managers/#creating-a-manager-with-queryset-methods" rel="nofollow"><code>as_manager</code> classmethod</a>.</p>

<pre><code>class PostQuerySet(models.QuerySet):
    def active(self):
        return self.filter(status=2)

class Post(models.Model):
    objects = PostQuerySet.as_manager()
</code></pre>

python django