orm查询基本操作

orm  ----关系对象模型

orm 的查询两种操作

1.基于对象的查询

oneTo one

一对多

和多对多

对象.关联字段

对象.表名(_set))

2.基于QUERYset的查询

双下划线即为跨表查询操作

3.基本操作

1.结果是对象的

get();first();last()

条件如果是多个会报错=

2.结果是Queryset的

filter();values(),value_list();all();annote();exclude(),distinct();order_by();reverse()

注意

order_by('-id','age')先按照id降序然后再按age升序
3.功能相关

exists();count()

4.聚合和分组
aggregate(average_price=Avg('price'))

annotate(author_num=Count("author"))

4.过滤条件:

 lt gt in contains  icontains  isnull   rangestartswith,istartswith, endswith, iendswith,regex,data,year month,weekday   hour minute second

原文地址:https://www.cnblogs.com/zjchao/p/8534460.html