On Thu, Dec 8, 2011 at 8:45 PM, wgis <alpha.sh...@gmail.com> wrote: > Ian Clelland, it worked! Thanks a lot for your perseverance > > Tom's secret sauce it's not working, unfortunately =( > Just (Carrots, Flavour, 3.0) > I guess since some 'contexts' don't have an associated thing-vote, the > filter will cut them off. > It would be more neat with the ORM, but I must be looking for a golden > a pot. >
That is strange; it wasn't supposition, it was actual results from a working project. Perhaps sqlite behaves differently to other DBs with that query, as you can see from this data and transcript, it does precisely what you asked for, using the ORM: sqlite> select * from app_thing; id name ---------- ---------- 1 carrot sqlite> select * from app_votecontext; id name ---------- ---------- 1 Flavour 2 Smell 3 Usability 4 Size sqlite> select * from app_vote; id thing_id context_id user_id vote ---------- ---------- ---------- ---------- ---------- 1 1 1 1 2 2 1 1 2 4 >>> from app.models import * >>> from django.db.models import * >>> carrot = Thing.objects.get(name='carrot') >>> u=User.objects.get(id=1) >>> f=(Q(vote__thing=carrot) | Q(vote__isnull=True))\ ... & (Q(vote__user=u) | Q(vote__isnull=True)) >>> qs = VoteContext.objects.filter(f) >>> qs = qs.annotate(vote_value=Sum('vote__vote')) >>> for ctxt in qs: print ctxt.name, ctxt.vote_value ... Flavour 2.0 Smell None Usability None Size None -- 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.