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