On Wed, Dec 7, 2011 at 5:09 PM, Tom Evans <tevans...@googlemail.com> wrote:
> Isn't this the secret sauce he is looking for?
>

Of course, I forget that the OP also wants to filter by a specific user:


>>> qs = VoteContext.objects.filter((Q(vote__thing=carrot) | 
>>> Q(vote__isnull=True)) & (Q(vote__user=u) | Q(vote__isnull=True)))
>>> qs = qs.annotate(vote_value=Sum('vote__vote'))
>>> for vote_ctxt in qs: print vote_ctxt.name, vote_ctxt.vote_value
...
Flavour 2.0
Smell None
Usability None
Size None
>>> qs = VoteContext.objects.filter((Q(vote__thing=carrot) | 
>>> Q(vote__isnull=True)) & (Q(vote__user=u2) | Q(vote__isnull=True)))
>>> qs = qs.annotate(vote_value=Sum('vote__vote'))
>>> for vote_ctxt in qs: print vote_ctxt.name, vote_ctxt.vote_value
...
Flavour 4.0
Smell None
Usability None
Size None

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to