user3541631
user3541631

Reputation: 4008

Using Custom Queryset as manager, filter again after a custom filtered method

I have a custom QuerySet:

class EntityModelQuerySet(models.query.QuerySet):

    def active(self):
        return self.filter(is_active=True)

In the model, I sent the QuerySet to work as manager:

class Entity(models.Model):
 is_active = models.BooleanField(default=False)
 objects = EntityModelQuerySet.as_manager()

In View I try:

Entity.objects.active.filter(is_home=True)

It gives me an error:

'function' object has no attribute 'filter'

Why, how to fix it ?

Upvotes: 0

Views: 70

Answers (1)

neverwalkaloner
neverwalkaloner

Reputation: 47364

You need to call active function to return queryset, just add ():

Entity.objects.active().filter(is_home=True)

Upvotes: 2

Related Questions