I can't make my custom manager 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 doesnt 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 might be going wrong?
I'm sure the problem is the get_query_set
method. This is the doc for version 1.5 managers and it says:
You can override a Manager‘s base QuerySet by overriding the Manager.get_query_set() method. get_query_set() should return a QuerySet with the properties you require.
Try to do it with get_query_set
instead of get_queryset
which is how it is explained in the dev doc:
You can override a Manager‘s base QuerySet by overriding the Manager.get_queryset() method. get_queryset() should return a QuerySet with the properties you require.
If you want to be 100% positive about how the method is named in your version just go to your Manager
class definition in django/db/models/manager.py
and search how is named the method in the class.
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With