Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

django query multiple conditions

from django.db.models import Q

 	criterion1 = Q(UID=request.user.id) #any query you want
    criterion2 = Q(FID=user.id) #any query you want
    criterion3 = Q(FID=request.user.id) #any query you want
    criterion4 = Q(UID=user.id) #any query you want
    areTheyFriends = Friends.objects.filter(criterion1 & criterion2 | criterion3 & criterion4) # use `&` and `|` logical operators
 
PREVIOUS NEXT
Tagged: #django #query #multiple #conditions
ADD COMMENT
Topic
Name
2+1 =