Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

django filter multiple conditions

from django.db.models import Q

ticket_query = request.event.tickets.filter(Q(status='on-sale') | Q(status='paused')).prefetch_related('ticket_tax')
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe in python 
Python :: camel case in python 
Python :: python print string name in pattern 
Python :: getters and setters in python 
Python :: python is inf 
Python :: tkinter entry focus 
Python :: python run in another thread decorator 
Python :: PhoneNumberField django forms 
Python :: bs4 class 
Python :: reverse element in a list in python 3 
Python :: check if file is txt python 
Python :: How to select parts of a numpy array 
Python :: read a file python 
Python :: how to display values on top of bar in barplot seaborn 
Python :: dataframe to ftp 
Python :: jupyter notebook show full dataframe cell 
Python :: count proportion pandas 
Python :: font in tkinter 
Python :: python array methods 
Python :: break all loops 
Python :: python create a grid of points 
Python :: python download file from url requests 
Python :: capitalize first letter of each word python 
Python :: delete element list python 
Python :: python alphabetical order 
Python :: python combine two lists into matrix 
Python :: convert to datetime object 
Python :: replace list 
Python :: python create array 
Python :: drop row with condition dataframe 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =