Quantcast
Channel: How to combine multiple querysets in Django? - Stack Overflow
Viewing all articles
Browse latest Browse all 32

Answer by Daniel Diaz for How to combine multiple querysets in Django?

$
0
0

The best option is to use the Django built-in methods:

# Union methodresult_list = page_list.union(article_list, post_list)

That will return the union of all the objects in those querysets.

If you want to get just the objects that are in the three querysets, you will love the built-in method of querysets, intersection.

# intersection methodresult_list = page_list.intersection(article_list, post_list)

Viewing all articles
Browse latest Browse all 32

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>