django,orm,or,q-object
from django.db.models import Q
사실 Q 연산은 or 뿐아니라 굉장히 많은 기능들을 할 수 있다.(거의 모든 쿼리에 대한 것들을..)
문서의 예제를 보자.
get(
Q(question__startswith='Who') | Q(question__startswith='What')
)
WHERE question LIKE 'Who%' OR question LIKE 'What%'
Q라는 함수에 파라미터를 넣어주게되는데 __startsWith
가 like 문이 되고 |
기호가 or연산이 된다.
다른 예로는..
get(
Q(question__startswith='Who'),
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
)
WHERE question LIKE 'Who%'
AND (pub_date = '2005-05-02' OR pub_date = '2005-05-06')