On Mon, Aug 18, 2014 at 1:06 PM, <
9dev...@gmail.com> wrote:
> Is it possible to annotate two different values to one QuerySet?
>
> Example queryset:
>
> Item.objects.annotate(score=Count('votes'))
Yes, simply pass it as an additional argument to annotate(). An
example from one of my projects:
shows = TVSeries.objects.all().order_by('name').annotate(
num_episodes=Count('tvepisode'),
num_episodes_with_media=Count('tvepisode__media_id'),
num_aired_episodes=Count('tvepisode__airdate'),
num_seasons=Max('tvepisode__season'))
So it counts the number of episodes, how many have media, how many
have aired, and what the maximum season is for each series.
>
> I would like every item in the above QuerySet to contain the following
> field:
>
> current_user_vote = Vote.objects.filter(user=request.user).filter(item=item)
As an aside, this can probably be written as:
current_user_vote = item.vote_set.filter(user=request.user)
>
> I tried to use annotate() two times, however it filtered out everything
> except items current user voted on.
Just use it once.
Cheers
Tom