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.

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store