Open caumons opened 11 years ago
The filtering strategy (see README) only supports true querysets, as it leaves it up to the DB to retrieve the proper objects for the page. This will not work when you start chaining together things.
So, your best bet is to use the slicing strategy. This has been tested with both lists and querysets. To make it work with iterators you may need to detect the iterator and turn it into a list so that it can be sliced, over here:
https://github.com/pennersr/django-pagemore/blob/master/pagemore/templatetags/pagemore.py#L106
I've done further investigations on this issue. At the moment of reporting it I was already using the slice strategy.
My conclusion is that using a chain object is "a pain in the ass". The main reason is than once you have iterated over its elements, you can't rewind the pointer, so you can't iterate it again and we need to do this here. So I'm afraid using chain objects would be a really hard implementation, if really possible. See following question in SO:
http://stackoverflow.com/questions/18232132/python-itertools-chain-object-has-no-attribute-getitem
Then, if chained objects are actually impossible to use, the best approach seems to be a real list
object, containing the items to be paginated (not querysets). The main problem here is the high use of memory if there are thousands of records involved. In the following question in SO (below), I haven't found a better way to do this than using lists. What I'm doing now to avoid really huge use of resources is to actually limit the queries, before calling list
on the chained querysets.
items_to_paginate = list(itertools.chain(queryset_1, queryset_2, queryset_3))
When using a "chained queryset" to do the pagination (obtained through
itertools.chain
method) the following exception is raised:Exception Value: 'itertools.chain' object has no attribute '__getitem__'
.Is there an easy way to get it working? I'm not sure if calling
list()
on the chained object before calling pagemore would be the best solution, because it will evaluate the queryset and this could cause a lot of overhead :S Thanks in advance!Here's the full stacktrace: