- filter熬芜,精確匹配,=
Author.objects.filter(id="1")
#select xxx from author where id="1"
- exclude曙强,取反残拐!=
Author.objects.exclude(id="1")
#select xxx from author where id != "1"
- __exact,精確匹配 like "xxx"
Author.objects.filter(name__exact="yang")
#select xxx from author where name like "yang"
- __iexact碟嘴,精確匹配溪食,忽略大小寫(xiě) like "xxx"
Author.objects.filter(name__iexact="YANG")
#select xxx from author where name like "YANG"
- __contains,模糊匹配娜扇,like "%xxx%"
Author.objects.filter(name__contains="yang")
#select xxx from author where name like "%yang%"
- __icontains错沃,忽略大小寫(xiě)模糊匹配
用法同上
- __gt,大于
Author.objects.filter(id__gt="1")
#select xxx from author where id > 1
- __gte雀瓢,大于等于
用法同上
__lt枢析,小于
__lte,小于等于
__in刃麸,在一個(gè)list范圍內(nèi)
Author.objects.filter(id__in=[1,2,3,4,5])
#select xxx from author where id in (1,2,3,4,5)
- __startswith醒叁,以xxx開(kāi)頭
Author.objects.filter(name__startswith="y")
#select xxx from author where name like "y%"
__istartswith, 以xxx開(kāi)頭,忽略大小寫(xiě)
__endswith把沼,以xxx結(jié)尾
__iendswith啊易,以xxx結(jié)尾,忽略大小寫(xiě)
__range饮睬,在xxx范圍內(nèi)
Author.objects.filter(id__range=[1,10])
#select xxx from author where id >= 1 and id <= 10
- __year租谈,日期字段的年份
Author.objects.filter(create_date__year="2015")
- __month 日期字段的月份
- __day 日期字段的日