Django ORM相当于'或'?

时间:2018-01-23 15:55:05

标签: python sql django orm django-orm

我需要在django orm中这样做。

SELECT * FROM offer WHERE country_id = 1 OR mundial = 1;

如何在django中执行'OR',如:

list = offer.objects.filter(country_id=1, #HOW DO I PUT 'OR' HERE?)

1 个答案:

答案 0 :(得分:4)

使用Q

from django.db.models import Q
list = offer.objects.filter(Q(country_id=1) | Q(something_else=1))