- 增加:创建实例,并调用save
- 更新:a.获取实例,再sava;b.update(指定列)
- 删除:a. filter().delete(); b.all().delete()
- 获取:a. 单个=get(id=1) ;b. 所有 = all()
- 过滤:filter(name=‘xxx‘);filter(name__contains=‘‘);(id__in = [1,2,3]) ;
icontains(大
小写无关的LIKE),startswith和endswith, 还有range(SQLBETWEEN查询)‘gt‘, ‘in‘,
‘isnull‘, ‘endswith‘, ‘contains‘, ‘lt‘, ‘startswith‘, ‘iendswith‘,
‘icontains‘,‘range‘, ‘istartswith‘ - 排序:order_by("name") =asc ;order_by("-name")=desc
- 返回第n-m条:第n条[0];前两条[0:2]
- 指定映射:values
- 数量:count()
- 聚合:from django.db.models import Min,Max,Sum objects.all().aggregate(Max(‘guest_id‘))
- 原始SQL
12
3
cursor
=
connection.cursor()
cursor.execute(‘‘
‘SELECT DISTINCT first_name ROM people_person WHERE last_name = %s""", [‘
Lennon‘])
row
=
cursor.fetchone()
时间: 2024-10-12 22:08:01