Answer the question
In order to leave comments, you need to log in
Explain the python code structure below?
New to python and django.
Please explain the syntax of the code given below, and where can I read about such constructions .values() .annotate() ...? Well, at the same time the semantic load of this code.
response.context_data['summary'] = list(
qs
.values('sale__category__name')
.annotate(**metrics)
.order_by('-total_sales')
)
Answer the question
In order to leave comments, you need to log in
Django ORM. It has fluent interface. I guess this example does some aggregation actions (in metrics), groups them by sale__category__name and sorts by total_sales in descending order, where total_sales is some kind of aggregation function that you didn’t write (most likely Sum of something)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question