Haki Benita
1 min readMar 27, 2018

--

Hey TheSupericedragon,

The metrics is just a dict of annotations.

This:

metrics = {
‘total’: Count(‘id’),
‘total_sales’: Sum(‘price’),
}
response.context_data[‘summary’] = list(
qs
.values(‘sale__category__name’)
.annotate(**metrics)
.order_by(‘-total_sales’)
)

is equivalent to

response.context_data[‘summary’] = list(
qs
.values(‘sale__category__name’)
.annotate(
total=Count(‘id’),
total_sales=Sum(‘price’),
)

.order_by(‘-total_sales’)
)

Hope this helps.

--

--

Haki Benita
Haki Benita

Written by Haki Benita

Full Stack Developer, Team Leader, Independent. More from me at https://hakibenita.com

No responses yet