Monday, August 18, 2014

How to annotate many values in one queryset

Is it possible to annotate two different values to one QuerySet?

Example queryset:

Item.objects.annotate(score=Count('votes'))

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)

I tried to use annotate() two times, however it filtered out everything except items current user voted on.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f63fafa-d224-4b25-875e-5d2c73c2e0f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment