我正在寻找正确的语法:
SomeModel.objects.filter(propertyA = 'foo' OR propertyB = 'bar')
这里的正确语法是什么?
看这里:https ://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects
这将是 :
from django.db.models import Q
SomeModel.objects.filter(Q(propertyA=foo) | Q(propertyB=bar))
使用Q 对象:
from django.db.models import Q
SomeModel.objects.filter(Q(propertyA='foo') | Q(propertyB='bar'))