In Django, I use the paginator like the following:
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
def myView(request):
...
paginator = Paginator(Annonce.objects.filter(name="huhu"), 10)
paginator._count = s.count()
try:
annonces = paginator.page(page)
except PageNotAnInteger:
annonces = paginator.page(1)
except EmptyPage:
annonces = paginator.page(paginator.num_pages)
In the s.search() function I do a query on my postgres db.
It turns out that even if I display 10 items per page, the query is not limited.
I tried to limit the query with a Annonce.objects.filter(name="huhu")[:10]
and specifying the count myself. But the paginator doesn't work if I do so.
Is there a way to optimize this?