book = BookInfo.objects.get(btitle='⻄游记') #单⼀查询,如果结果不存在报错
book = BookInfo.objects.all() #查询多个结果,有多少返回多少,不存在返回None
book = BookInfo.objects.filter(btitle='⻄游记').count() #查询结果的数量
book = BookInfo.objects.exclude(btitle='⻄游记') #查询结果取反
模糊查询:
# contains 是否包含
book = BookInfo.objects.filter(btitle__contains='记') #查询结果包
含‘记’ %记%
# startswith,endswith 以指定值开头或结尾
book = BookInfo.objects.filter(btitle__startswith='⻄') #查询以‘⻄’开
头的 ⻄%
book = BookInfo.objects.filter(btitle__endswith='记') #查询以‘记’结尾
的 %记
空查询:
# isnull 是否为空
book = BookInfo.object.filter(bititle__isnull=Flase) #查询bititle不为空
范围查询:
# in 在范围内
# range 相当于between...and...
book = BookInfo.object.filter(id__in = [1,5,13,24]) #查询id为1或5或13或24
book = BookInfo.object.filter(id__range = [10,20]) #查询范围为10-20的id