Annotations: fix basic query generation

The modifications of the queryset generation I added in 006228b were
wrong and did not work as expected. We should start to use some unit
tests for these things. This commit fixes the queryset generation and
makes it more straight forward to understand. It fixes #667.