开发者

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

开发者 https://www.devze.com 2023-01-20 00:16 出处:网络
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.

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 uniqu开发者_Go百科e properties of Set to solve the problem either. any ideas?


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消