Paginator has many Pages, but all are empty?

8 views
Skip to first unread message

ch3ka

unread,
Oct 11, 2011, 12:55:07 PM10/11/11
to Django users
I have a problem with django.core.paginator.

I have a Page object who's .object_list is [], but at the same time
it's repr() states "Page 1 of 11".

How is that even possible?

Same with page 2, page 3 ,...

Daniel Roseman

unread,
Oct 12, 2011, 4:52:04 PM10/12/11
to django...@googlegroups.com
You'll have to show some code. How are you creating the page object? 
-- 
DR. 

ch3ka

unread,
Oct 13, 2011, 6:37:53 AM10/13/11
to Django users
On Oct 12, 10:52 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:

> You'll have to show some code. How are you creating the page object?

hotels =
Hotel.objects.select_related().filter(is_deleted=False).filter(...)...
paginator = Paginator(hotels[:200], items_per_page)
try: page = int(request.GET.get('page', '1'))
except ValueError: page = 1
try:
hotel_list = paginator.page(page)
except (EmptyPage, InvalidPage):
hotel_list = paginator.page(paginator.num_pages)
print hotel_list.paginator.num_pages # yields 11, which is expected
for the query
print hotel_list # yields "Page 1 of 11", which is again expected
print hotel_list.object_list # yields [], WTF

I resolved the problem meanwhile by simply reverting the DB to an
older state, seems like there was something wrong with the data
consistency there.
But still I'd like to know how it's possible that Paginator behaves
like this.
Reply all
Reply to author
Forward
0 new messages