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 :: makemigration django 
Python :: pytube python 
Python :: boxplot python 
Python :: dash log scale 
Python :: sphinx autodoc command 
Python :: python loc 
Python :: change markersize in legend matplotlib 
Python :: how to count substring in a string in python 
Python :: pandas transform 
Python :: df concat multiple columns 
Python :: python dataframe calculate difference between columns 
Python :: float64 python 
Python :: seaborn distribution plot for all columns 
Python :: remove item from list 
Python :: write python 
Python :: snake water gun game in python 
Python :: replace nan 
Python :: py one line function 
Python :: multiple input to list 
Python :: select rows with multiple conditions pandas query 
Python :: ip address finder script python 
Python :: All Details in python stack 
Python :: pandas subplots 
Python :: link_to class 
Python :: python try catch print stack 
Python :: python if not 
Python :: pd.concat in python 
Python :: python delete list elements 
Python :: radix sort strings python 
Python :: python how to use logarithm 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =