As quoted by ruddra
You can use union() to combine different querysets like this:
q1_projects = Model.objects.filter(...)
q2_projects = Model.objects.filter(...)
q3_projects = Model.objects.filter(...)
projects = q1_projects.union(q2_projects, q3_projects)
That will give same result as:
projects = q1_projects & q2_projects & q3_projects
Note: The UNION
operator selects only distinct values by default. To allow duplicate values, use the all=True
argument.
But if you want to order_by
on the ForeignKey, you have to use select()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…