【问题标题】:Apply OR logic on Q objects query in a list对列表中的 Q 对象查询应用 OR 逻辑
【发布时间】:2018-05-03 07:57:22
【问题描述】:

我希望对 expertiseParams 中的元素列表应用 OR 查询

我的代码是:

queryset_list = Profile.objects.all()

for expertise in expertiseParams:
            queryset_list = queryset_list.filter(Q(expertisematch__expertise=expertise))

我的问题是:如何在过滤的所有 Q 对象上实现 OR 逻辑? 谢谢!

【问题讨论】:

  • 你在找filter(expertisematch__expertise__in=expertiseParams)吗?
  • 不,我希望对所有 qeries 执行 OR 逻辑

标签: python sql django


【解决方案1】:

谢谢@Sayse!

答案是这样的:

queryset_list = Profile.objects.all()
queryset_list =queryset_list.filter(expertisematch__expertise__in=expertiseParams)

【讨论】:

    猜你喜欢
    • 2018-12-14
    • 2015-03-03
    • 2013-01-20
    • 2015-05-13
    • 1970-01-01
    • 2014-03-25
    • 2017-09-16
    • 2016-02-02
    • 2014-02-06
    相关资源
    最近更新 更多