Django
常用操作
Django生产设置
Setting设置
装饰器
类
类--验证登陆
ListView
CreateView
DeleteView
URL方法
Views方法
model数据模型
models
admin
views
url
model查询操作
model聚合查询
model列操作及复杂查询
登录退出
登陆成功后跳转指定页面
修改密码
重置密码
分页
标签
HTML文件
开启HTTPS
CSRF
本文档使用MrDoc发布
返回首页
-
+
model聚合查询
2020年11月11日 11:46
admin
#view文件写法: UserData.objects.filter(hubid=sensorid,time__range=(time2,time1)).values('hour').annotate(sum_out=Sum('outdoor'), sum_in=Sum('indoor'), sum_eat=Sum('kitchen'), sum_wash=Sum('toilet')).order_by('hour') #SQL写法: select Sum('outdoor') as sum_out,Sum('indoor') as sum_in,Sum('kitchen') as sum_eat,Sum('toilet') as sum_wash,hour where hubid='sensorid' and (time between time1 and time2) group by hour order by hour asc #view文件写法:(多条件) UserData.objects.filter(hubid=sensorid,time__range=(time2,time1)).values('hour','name').annotate(sum_out=Sum('outdoor'), sum_in=Sum('indoor'), sum_eat=Sum('kitchen'), sum_wash=Sum('toilet')).order_by('hour') #SQL写法:(多条件) select Sum('outdoor') as sum_out,Sum('indoor') as sum_in,Sum('kitchen') as sum_eat,Sum('toilet') as sum_wash,hour where hubid='sensorid' and (time between time1 and time2) group by hour,name order by hour asc
分享到: