django orm 操作符

__gt 大于
__gte 大于等于
__lt 小于
__lte 小于等于
__in
__exact 精确等于 like 'aaa'
__iexact 精确等于 忽略大小写 ilike 'aaa'
__contains 包含 like '%aaa%'
__icontains 包含 忽略大小写 ilike '%aaa%'
is null / is not null
User.objects.filter(username__isnull=True) // 查询用户名为空的用户
User.objects.filter(username__isnull=False) // 查询用户名不为空的用户
User.objects.filter().excute(age=10) // 查询年龄不为10的用户
User.objects.filter().excute(age__in=[10, 20]) // 查询年龄不为在 [10, 20] 的用户

_exact 精确等于 like 'aaa'
__iexact 精确等于 忽略大小写 ilike 'aaa'
__contains 包含 like '%aaa%'
__icontains 包含 忽略大小写 ilike '%aaa%',但是对于sqlite来说,contains的作用效果等同于icontains。
__gt 大于
__gte 大于等于
__lt 小于
__lte 小于等于
__in 存在于一个list范围内
__startswith 以...开头
__istartswith 以...开头 忽略大小写
__endswith 以...结尾
__iendswith 以...结尾,忽略大小写
__range 在...范围内
__year 日期字段的年份
__month 日期字段的月份
__day 日期字段的日
__isnull=True/False

原文地址:https://www.cnblogs.com/ExMan/p/9444464.html