case when with multiple condition queryset django code example
Example: 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