V
V
VkolV2020-11-23 20:22:38
Django
VkolV, 2020-11-23 20:22:38

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')
        )

taken from this article
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2020-11-23
@VkolV

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 question

Ask a Question

731 491 924 answers to any question