How to use in conjunction with django.core.paginator
HowardHoulston opened this issue · 2 comments
HowardHoulston commented
I really like this project and use it a lot, however I am struggling to work out how to use it in conjunction with the django paginator, so I end up with code like this:
paginator = Paginator(fetch(my_object_list), 20)
As such the object list is fetched with all records rather than the limited set that the paginator would usually call. Do you have any guidance on how to use zen queries with a paginator? I have done searches and cannot find anything online regarding this.
HowardHoulston commented
Ah right - worked this one out - apologies for time wasting!
paginator = Paginator(my_object_list, 20)
try:
page_obj = paginator.page(page)
except PageNotAnInteger:
page_obj = paginator.page(1)
except EmptyPage:
page_obj = paginator.page(paginator.num_pages)
items = fetch(page_obj.object_list.all())
return render(request, 'my_template.html', {
'items': items,
'page_obj': page_obj,
... etc ...
})
j4mie commented
Cool - glad you sorted it! I might stick your example in the README at some point. Thanks!