What's this after aggregation in django?
<p>I see the following code from a django project. I understand it's aggregation, but what's ['kw__sum'] after the aggregation?</p>

<pre><code>Project.objects.filter(project = project).aggregate(Sum('kw'))['kw__sum']
</code></pre>

<p>Thanks</p>

<p>Here if you look in <a href="https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet" rel="nofollow">examples</a> you will see that <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#aggregate" rel="nofollow"><code>aggregate</code></a> returns dictionary so last part is just dict lookup</p>

<pre><code>aggregation = Project.objects.filter(project = project).aggregate(Sum('kw'))
result = aggregation['kw__sum']
</code></pre>

<p>From the docs</p>

<blockquote>
  <p>Returns a dictionary of aggregate values (averages, sums, etc.) calculated over the QuerySet. Each argument to aggregate() specifies a value that will be included in the dictionary that is returned.</p>
</blockquote>

python django aggregation