模型基础二-mysql

一、常用查询及表关系的实现

1.常用查询

  常用查询方法:

  常用查询条件:

  常用字段类型:

  字段类型映射关系:

 1.1 objects是模型的管理器,类名+objects+方法

  all方法:

  first  and last方法:

  get方法(只能查询一个数据,条件符合多个或者不存在,则会报错):

  filter方法:

  exlude方法:

  order_by方法:

  切片方法:

  values方法(以字典类型返回):

  only and defer方法:

  count方法(统计个数):

  多条件查询or链接:

1.2   用双下划线__ 连接条件查询:

  exact, gt, lt:

  startwith,endswith,istartswith,iendswith:

  rang,in,isnull:

1.3  聚合函数,先倒入方法,使用:(类名+objects+aggregate+函数):

  Avg平均值,Sum求和,Max最大值,Min最小值:

  

  

  

猜你喜欢

转载自www.cnblogs.com/18zirenqing/p/10666105.html