0

I got a query currently looking like this:

x = Model.objects.values("city").annotate(Sum("a")).annotate(Sum("b"))

city is a choicefield, which means I need to do get_FOO_display() on it, but I can't as values() returns a non-query set of a list of tuples, so everything’s evaluated there already.

If I change values() to filter() or only() it works, but assuming I got 2 db inputs, one adding 500 to a and one adding 500 to b, then it would create two rows in my table in the template, instead of summing both fields in same row.

How could I get the value from my choicefield and sum both values in the same row?

Jannickla
  • 27
  • 5
  • Does this answer your question? [Django Aggregation: Summation of Multiplication of two fields](https://stackoverflow.com/questions/12165636/django-aggregation-summation-of-multiplication-of-two-fields) – Nicolae May 26 '21 at 15:33
  • No, I try to have three cols in a row, city, sum a and sum b. Not to multiply them. – Jannickla May 26 '21 at 15:47

0 Answers0