UPDATE
Thanks to the posted answer, I found a much simpler way to formulate the problem. The original question can be seen in the revision history.
Your problem comes from values()
follow by annotate()
. Order are important.
This is explain in documentation about [order of annotate and values clauses](
https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#order-of-annotate-and-values-clauses)
.values('pub_id')
limit the queryset field with pub_id
. So you can't annotate on income
The values() method takes optional positional arguments, *fields, which specify field names to which the SELECT should be limited.