单表的双下划线
import os if __name__ == '__main__': os.environ.setdefault("DJANGO_SETTINGS_MODULE", "about_orm.settings") import django django.setup() from app01 import models ret = models.Person.objects.filter(nid__gt=1) # greater than ret = models.Person.objects.filter(nid__gte=1) # greater than equal ret = models.Person.objects.filter(nid__lt=2) # less than ret = models.Person.objects.filter(nid__lte=2) # less than equal ret = models.Person.objects.filter(nid__in=[1,3]) ret = models.Person.objects.filter(nid__range=[1,3]) ret = models.Person.objects.filter(name__contains='a') ret = models.Person.objects.filter(name__icontains='a') # 忽略大小写 ret = models.Person.objects.filter(name__startswith='a') # 忽略大小写 ret = models.Person.objects.filter(birth__year=2018) # 忽略大小写 ret = models.Person.objects.filter(birth__month=12) # 忽略大小写 ret = models.Person.objects.filter(birth__contains='2019-02') # 忽略大小写 ret = models.Person.objects.filter(name__isnull=True) # 字段为空 ret = models.Person.objects.filter(name__isnull=False) # 字段为空 print(ret)
作者:wangkaiok —— 小菜鸟111
出处:http://www.cnblogs.com/wangkaiok/
本文版权归作者和博客园共有,但未经作者同意禁止转载,转载必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。