1 # 获取个数 2 # 3 # models.Tb1.objects.filter(name=‘seven‘).count() 4 5 # 大于,小于 6 # 7 # models.Tb1.objects.filter(id__gt=1) # 获取id大于1的值 8 # models.Tb1.objects.filter(id__lt=10) # 获取id小于10的值 9 # models.Tb1.objects.filter(id__lt=10, id__gt=1) # 获取id大于1 且 小于10的值 10 11 # in 12 # 13 # models.Tb1.objects.filter(id__in=[11, 22, 33]) # 获取id等于11、22、33的数据 14 # models.Tb1.objects.exclude(id__in=[11, 22, 33]) # not in 15 16 # contains 17 # 18 # models.Tb1.objects.filter(name__contains="ven") 19 # models.Tb1.objects.filter(name__icontains="ven") # icontains大小写不敏感 20 # models.Tb1.objects.exclude(name__icontains="ven") 21 22 # range 23 # 24 # models.Tb1.objects.filter(id__range=[1, 2]) # 范围bettwen and 25 26 # 其他类似 27 # 28 # startswith,,istartswith, endswith, iendswith, 29 30 # order by 31 # 32 # models.Tb1.objects.filter(name=‘seven‘).order_by(‘id‘) # asc 从小到大 33 # models.Tb1.objects.filter(name=‘seven‘).order_by(‘-id‘) # desc 从大到小 34 35 # limit 、offset 36 # 37 # models.Tb1.objects.all()[10:20] 38 39 # group by 40 from django.db.models import Count, Min, Max, Sum 41 # models.Tb1.objects.filter(c1=1).values(‘id‘).annotate(c=Count(‘num‘)) 42 # SELECT "app01_tb1"."id", COUNT("app01_tb1"."num") AS "c" FROM "app01_tb1" WHERE "app01_tb1"."c1" = 1 GROUP BY "app01_tb1"."id"