查询价格大于200的书籍
res = models.Book.objects.filter(price__gt=200)
print(res)
查询价格小于200的书籍
res = models.Book.objects.filter(price__lt=200)
print(res)
查询价格大于等于200.22的书籍
res = models.Book.objects.filter(price__gte=200.22)
print(res)
查询价格小于等于200.22的书籍
res = models.Book.objects.filter(price__lte=200.22)
print(res)
查询价格要么是200,要么是300,要么是666.66
res = models.Book.objects.filter(price__in=[200,300,666.66])
print(res)
查询价格在200到800之间的
res = models.Book.objects.filter(price__range=(200,800)) # 两边都包含
print(res)
查询书籍名字中包含p的
原生sql语句 模糊匹配
like
%
_
"""
res = models.Book.objects.filter(title__contains='p') # 仅仅只能拿小写p
res = models.Book.objects.filter(title__icontains='p') # 忽略大小写
print(res)
查询书籍是以三开头的
res = models.Book.objects.filter(title__startswith='三')
res1 = models.Book.objects.filter(title__endswith='p')
print(res)
print(res1)
查询出版日期是2017的年(******)
res = models.Book.objects.filter(create_time__year='2017')
print(res)