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.