实训第八天 有关python orm 的学习记录 常用方法02
继续沿用第七天数据库:
def test2(request):
# 1.xxx__lt 小于 :查询出年龄小于22的所有
ret=models.Person.objects.filter(age__lt=22)
print(ret)
# 2.xxx__lte 小于等于
ret=models.Person.objects.filter(age__lte=22)
print(ret)
# 3.xxx__gt 大于:
ret = models.Person.objects.filter(age__gt=21)
print(ret)
# 4.xxx__gte 大于等于:
ret = models.Person.objects.filter(age__gte=21)
print(ret)
# 5.xx__in=[] 包含某些值
ret = models.Person.objects.filter(age__in=[21, 23, 33])
print(ret)
# 6.xx__contains= 包含内容
ret = models.Person.objects.filter(name__contains='l')
print(ret)
# 7.xxx__startswith= 查询出以某个字符 开始的对象
ret = models.Person.objects.filter(name__startswith='l')
print(ret)
# 8.xx__endswitn= 查询出以 某个字符串结束的对象
ret = models.Person.objects.filter(name__endswith='x')
print(ret)
return HttpResponse('第八天的常用方法___双下划线方法')