Categories
Python Answers

How to find the union of two Python Django querysets?

Spread the love

Sometimes, we want to find the union of two Python Django querysets.

In this article, we’ll look at how to find the union of two Python Django querysets.

How to find the union of two Python Django querysets?

To find the union of two Python Django querysets, we use the | operator.

For instance, we write

records = query1 | query2

If we want distinct values, we write

records = (query1 | query2).distinct()

Conclusion

To find the union of two Python Django querysets, we use the | operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *