find.py
variable=Model name.objects.filter(Filter contents)
samle.py
variable=Model name.objects.filter(Filter contents)
#Perfect matching
variable=Model name.objects.filter(item name=value)
#Starts with a value
variable=Model name.objects.filter(item name__startswith=value)
#Search for things that end in a value
variable=Model name.objects.filter(item name__endswith=value)
#Fuzzy search
variable=Model name.objects.filter(item name__contains=value)
#Search regardless of size
variable=Model name.objects.filter(item name__iexact=value)
#Fuzzy search that does not distinguish between large and small
variable=Model name.objects.filter(item name__icontains=value)
variable=Model name.objects.filter(item name__istartswith=value)
variable=Model name.objects.filter(item name__iendswith=value)
sample.py
variable=Model name.objects.filter(Filter contents)
#Equal to value
variable=Model name.objects.filter(item name=int(value))
#Greater
variable=Model name.objects.filter(item name__gt=int(value))
#that's all
variable=Model name.objects.filter(item name__gte=int(value))
#Smaller
variable=Model name.objects.filter(item name__lt=int(value))
#Less than
variable=Model name.objects.filter(item name__lte=int(value))
sample.py
variable=Model name.objects.filter(First condition,Second condition,...)
variable=Model name.objects \
.filter(First condition) \
.filter(Second condition) \
sample.py
variable=Model name.objects.filter(Q(First condition)|Q(Second condition),...)
sample.py
variable=Model name.objects.filter(item name__in=list)
sample.py
variable=Model name.objects.raw(sql statement)
#sql statement
sql = 'SELECT *FROM table name'
##table name
Application name_Model name
Recommended Posts