You need to include “ownProduction” in your values list prior to the annotation.
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Mikkel Kromann Sent: Monday, August 13, 2018 3:22 PM To: Django users Subject: GROUP BY I'm trying to sum the field "ownProduction", grouping it by the foreign key "market" (using the market's human readable name, __name from the Market table) and the week number (which is built-in function __year of the date field "dateContract"). However, when I try to read the results of the query in the last line in the code example below., I get the error: "'dict' object has no attribute 'ownProduction'" So "ownProduction" is to my surprise not a field in the query. What am I doing wrong? contract_query = (Project.objects.all() .filter(department=department_id) .filter(datePipeline__year=year) .filter(stage="WON") .annotate(week=ExtractWeek('dateContract')) .values('week','market__name') .annotate(Sum('ownProduction')) ) for contract_row in contract_query: contract_sum = contract_row.ownProduction It doesn't change anything using .annotate(ownProduction = Sum('ownProduction')) cheers + thanks, Mikkel -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com<mailto:django-users@googlegroups.com>. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/525b78b7-ada3-4a49-818a-c02fc1bf51b0%40googlegroups.com<https://groups.google.com/d/msgid/django-users/525b78b7-ada3-4a49-818a-c02fc1bf51b0%40googlegroups.com?utm_medium=email&utm_source=footer>. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e922b48260394f1f9d585c0dca743a5d%40ISS1.ISS.LOCAL. For more options, visit https://groups.google.com/d/optout.