To combine two or more querysets in a Python Django view, we can use the itertools chain
method.
For instance, we write
from itertools import chain
result_list = list(chain(page_list, article_list, post_list))
to call chain
with the page_list
, article_list
, and post_list
querysets.
Then we convert the combined querysets into a list with list
.