[Answer]-Concatenate queryset in django

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

Leave a comment