Django orm group by multiple columns

泪湿孤枕 提交于 2019-12-05 12:41:44
Shubhanshu
from django.db.models import Sum
Your_Model.objects.values('order_id', 'city', 'locality', 'login_time').order_by().annotate(sum('morning_hours'), sum('afternoon_hours'), sum('evening_hours'), sum('total_hours'))

I hope the above code snippet helps (While answering, I had no idea whether morning hours, afternoon hours, etc are derived columns or existing fields in the table, because you have specified nothing of the sort in your question. Hence, I made my assumption and have answered your question). For grouping by multiple columns, there already exists a question on SO. See this link.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!