Try not to use _ (underscore) character as prefix or postfix to any user defined variable or db column. Its not recommended in django.
On Tue 14 Aug, 2018, 1:52 AM Mikkel Kromann, <mik...@aabenhuskromann.dk> wrote: > 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. > 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/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/CAM-Jvq5e3d4AL-A03zDwOhEvedV-JPwSC%2BgNGSEgqnkvwrDpDA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.