django query multiple conditions

Solutions on MaxInterview for django query multiple conditions by the best coders in the world

showing results for - "django query multiple conditions"
Lina
20 Jan 2019
1from django.db.models import Q
2
3 	criterion1 = Q(UID=request.user.id) #any query you want
4    criterion2 = Q(FID=user.id) #any query you want
5    criterion3 = Q(FID=request.user.id) #any query you want
6    criterion4 = Q(UID=user.id) #any query you want
7    areTheyFriends = Friends.objects.filter(criterion1 & criterion2 | criterion3 & criterion4) # use `&` and `|` logical operators