django基础 --- models过滤条件

2016-12-13  本文已影响0人  梦想做小猿
Author.objects.filter(id="1")
#select xxx from author where id="1"
Author.objects.exclude(id="1")
#select xxx from author where id != "1"
Author.objects.filter(name__exact="yang")
#select xxx from author where name like "yang"
Author.objects.filter(name__iexact="YANG")
#select xxx from author where name like "YANG"
Author.objects.filter(name__contains="yang")
#select xxx from author where name like "%yang%"
用法同上
Author.objects.filter(id__gt="1")
#select xxx from author where id > 1
用法同上
Author.objects.filter(id__in=[1,2,3,4,5])
#select xxx from author where id in (1,2,3,4,5)
Author.objects.filter(name__startswith="y")
#select xxx from author where name like "y%"
Author.objects.filter(id__range=[1,10])
#select xxx from author where id >= 1 and id <= 10
Author.objects.filter(create_date__year="2015")
上一篇 下一篇

猜你喜欢

热点阅读