0

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?

killerbarney
  • 947
  • 10
  • 24

1 Answers1

4

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()
Chris Lawlor
  • 47,306
  • 11
  • 48
  • 68
  • interesting, thanks! unfortunately i'm using a backend that doesn't support the "OR" keyword, so it can't execute this as one query statement, but two completely separate ones. I haven't been able to figure out a way to use the distinct on two completely separate queries – killerbarney Oct 23 '10 at 18:00
  • 1
    Well, if you don't need a queryset in return, you could just do results = set(list(qs1) + list(qs2)). – Chris Lawlor Oct 26 '10 at 02:43