大于、大于等于

1
2
3
4
5
__gt 大于
__gte 大于等于
 
User.objects.filter(age__gt=10) // 查询年龄大于10岁的用户
User.objects.filter(age__gte=10) // 查询年龄大于等于10岁的用户

小于、小于等于

1
2
3
4
5
__lt 小于
__lte 小于等于
 
User.objects.filter(age__lt=10) // 查询年龄小于10岁的用户
User.objects.filter(age__lte=10) // 查询年龄小于等于10岁的用户

在...范围内

1
2
3
4
__in
 
查询年龄在某一范围的用户
User.objects.filter(age__in=[10, 20, 30]) 

模糊查询

1
2
3
4
__exact 精确等于 like 'aaa'
__iexact 精确等于 忽略大小写 ilike 'aaa'
__contains 包含 like '%aaa%'
__icontains 包含 忽略大小写 ilike '%aaa%',但是对于sqlite来说,contains的作用效果等同于icontains。

是否为空

1
2
3
is null / is not null
User.objects.filter(username__isnull=True// 查询用户名为空的用户
User.objects.filter(username__isnull=False// 查询用户名不为空的用户

不等于/不包含于

1
2
User.objects.filter().excute(age=10) // 查询年龄不为10的用户
User.objects.filter().excute(age__in=[10, 20]) // 查询年龄不为在 [10, 20] 的用户

 

不等于好像是exclude

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2020-01-08
  • 2022-02-07
  • 2022-01-17
  • 2021-10-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2022-02-16
  • 2021-09-03
相关资源
相似解决方案