1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| 大于、大于等于: __gt 大于> __gte 大于等于>=
Student.objects.filter(age__gt=10) // 查询年龄大于10岁的学生 Student.objects.filter(age__gte=10) // 查询年龄大于等于10岁的学生
like:
__exact 精确等于 like 'aaa' __iexact 精确等于 忽略大小写 ilike 'aaa' __contains 包含 like '%aaa%' __icontains 包含,忽略大小写 ilike '%aaa%',但是对于sqlite来说,contains的作用效果等同于icontains
in: __in
查询年龄在某一范围的学生 Student.objects.filter(age__in=[10, 20, 30])
is null / is not null
Student.objects.filter(name__isnull=True) // 查询用户名为空的学生 Student.objects.filter(name__isnull=False) // 查询用户名不为空的学生
不等于/不包含于:
Student.objects.filter().excute(age=10) // 查询年龄不为10的学生 Student.objects.filter().excute(age__in=[10, 20]) // 查询年龄不在 [10, 20] 的学生
其他常用模糊查询:
__startswith 以…开头 __istartswith 以…开头 忽略大小写 __endswith 以…结尾 __iendswith 以…结尾,忽略大小写 __range 在…范围内 __year 日期字段的年份 __month 日期字段的月份 __day 日期字段的日 Book.objects.filter(create_time__year=2019, create_time__month=4).all()
|