1👍
The itertools.chain()
will return a generator. The Paginator
class needs an object implementing __len__
(generators, of course do not support it since the size of the collection is not known).
Your problem could be resolved in a number of ways (including using list
to evaluate the generator as you mention) however I recommending taking a look at the QuerySetChain
mentioned in this answer:
https://stackoverflow.com/a/432666/119071
I think it fits exactly to your problem. Also take a look at the comments of that answer – they are really enlightening 🙂
0👍
I know it’s too late, but because I encountered this error, I would answer to this question.
you should return a list of objects:
ci = ContributorImage.objects.all()
pf = Portfolio.objects.all()
cpf = itertools.chain(ci,pf)
cpf_list = list(cpf)
👤Ali
- [Answer]-Elasticsearch/haystack not persisting across server restarts
- [Answer]-Playing audio through audio tag in a Django application
- [Answer]-How to translate this raw query to Django ORM
- [Answer]-Grabbing field from a query set in Django
- [Answer]-`&` character in database password gives error with django dbshell
Source:stackexchange.com