Issue
Here is SQL Query:
SELECT id, ip_src, ip_dst, src_port, ip_proto, sum(bytes) as Traffic
FROM table GROUP BY ip_src, ip_dst, ip_proto
ORDER BY 6 DESC limit 10;
I need to convert it in ORM Query. I know that there are raw sql queries in Django, but I need ORM in order to integrate this query with Chartit addon(Highcharts), which understands only querysets and models.
Got this, but it's not correct
Flow.objects.values('ip_src', 'ip_dst', 'ip_proto',
'bytes').annotate(traffic=Sum('bytes')).order_by('-traffic')[:10]
Any help is appreciated
Solution
Try this:
Flow.objects.values('ip_src', 'ip_dst', 'ip_proto').annotate(traffic=Sum('bytes')).order_by('-traffic')[:10]
Answered By - Anentropic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.