import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "about_orm.settings")
import django
django.setup()
from app01 import models
ret = models.Person.objects.all()
ret = models.Person.objects.filter(name=‘alexdsb‘)
ret = models.Person.objects.exclude(name=‘alexdsb‘)
ret = models.Person.objects.values(‘name‘,‘age‘)
ret = models.Person.objects.values_list(‘age‘,‘name‘)
ret = models.Person.pbjects.all().order_by(‘-age‘,‘pk‘)
ret = models.Person.objects.all().order_by(‘pk‘)
ret = models.Person.objects.all().order_by(‘pk‘).reverse()
ret = models.Person.objects.all().distinct()
ret = models.Person.objects.values(‘name‘,‘age‘).distinct()
ret = models.Person.objects.all().count()
ret = models.Person.objects.filter(name=‘alexdsb‘).count()
ret = models.Person.objects.filter(name=‘xx‘).first()
ret = models.Person.objects.values().last()
ret = models.Person.objects.filter(name=‘xx‘).exists()
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "about_orm.settings")
import django
django.setup()
from app01 import models
ret = models.Person.objects.filter(pk_gt=3) # gt greater than 大于
ret = models.Person.objects.filter(pk_lt=3) # lt less than 小于
ret = models.Person.objects.filter(pk_gte=3) # gte greater than equal 大于等于
ret = models.Person.objects.filter(pk_lte=3) # lte less than equal 小于等于
ret = models.Person.objects.filter(pk_range=[1,4]) # 范围
ret = models.Person.objects.filter(pk_in=[1,4]) # 成员判断
ret = models.Person.objects.filter(name_in=[‘alexdsb‘,‘xx‘])
ret = models.Person.objects.filter(name_contains=‘x‘) # contains 包含
ret = models.Person.objects.filter(name_icontains=‘X‘) # ignore contains 忽略大小写
ret = modles.Person.objects.filter(name_starswith=‘x‘) # 以什么开头
ret = models.Person.objects.filter(name_istartswith=‘X‘) # 忽略大小写
ret = models.Person.objects.filter(name__endswith=‘dsb‘) # 以什么开头
ret = models.Person.objects.filter(name__iendswith=‘DSB‘) # 以什么开头
ret = modles.Person.objects.filter(phone_isnull=Fales) # _isnull = False 不为Null
ret = models.Person.objects.filter(birth_year=‘2020‘)
ret = models.Person.objects.filter(birth_contains=‘2020-11-02‘)
原文:https://www.cnblogs.com/womenzt/p/12445682.html