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)