Django user manager get_queryset () not working

I can't get my user manager to work ...

class PublicArtigoManager(models.Manager): def get_queryset(self): return super(PublicArtigoManager, self).get_queryset().filter(data_publicacao__lte=timezone.now()).filter(permissao__lte=3) class Artigo(models.Model): ... objects = models.Manager() publics = PublicArtigoManager() 

when I test in the shell it doesn't work

 >>> from artigos.models import Artigo >>> from django.utils import timezone >>> print Artigo.objects.count() 9960 >>> print Artigo.publics.count() 9960 >>> print Artigo.objects.filter(data_publicacao__lte=timezone.now()).filter(permissao__lte=3).count() 9959 

Artigo.publics.count() should return 9959, right? Any ideas what could go wrong?

+7
source share
1 answer

I am sure the problem is with the get_query_set method. This is the document manager for version 1.5 , and he says:

You can override the base QuerySet manager by overriding the Manager.get_query_set () method. get_query_set () should return a QuerySet with the required properties.

Try this with get_query_set instead of get_queryset , as described in dev doc :

You can override the base manager QuerySet by overriding the Manager.get_queryset () method. get_queryset () should return a QuerySet with the required properties.

If you want to be 100% positive in how the method is named in your version, just go to the definition of the Manager class in django/db/models/manager.py and search for what the method is called in the class.

Hope this helps!

+10
source

All Articles