【发布时间】:2017-06-22 23:29:42
【问题描述】:
有没有办法在 Django 中获取一个 QuerySet,以便剩余的对象至少满足多个约束中的一个(即 OR 语句)?
类似:
remaining = Fruits.objects.all()
fruit_type = ['apple', 'orange'] # input from user
for fruit in fruit_type:
remaining = remaining.filter(FruitType__icontains=fruit)
但是,上面只返回同时包含 'orange' 和 'apple' 的 FruitTypes(而不是 orange OR apple)。
【问题讨论】: