通过OR而不是AND过滤QuerySet

时间:2011-06-01 22:00:15

标签: django django-models

如果我这样做:

People.filter(name = 'Oscar', lastName = 'Mederos)

它将被翻译成:

SELECT ______ WHERE Name = 'Oscar' AND LastName = 'Mederos

Django允许使用OR代替AND吗?

1 个答案:

答案 0 :(得分:6)

Q objects

People.objects.filter(Q(name='Oscar') | Q(lastName='Mederos'))