killerbarney
killerbarney

Reputation: 943

Django - Make two separate queries, combine the results, then eliminate duplicates

Is there a fast and easy way to do this? I haven't been able to find anything that's already out there that seems to do this already.

Since it's a queryset, i don't think i can use the unique properties of Set to solve the problem either. any ideas?

Upvotes: 0

Views: 1292

Answers (1)

Chris Lawlor
Chris Lawlor

Reputation: 48972

Use Q objects, one for each query, and OR them together. Then, use distinc()

qs = SomeModel.objects.get(Q(some_attribute=something) |
                           Q(some_other_attribute=something)).distinct()

Upvotes: 4

Related Questions