First, thank you both for your answers. I'm now realizing that doing
this with the ORM is not so easy as I thought it would be to others
django fellows (it's my first django project, but I'm nailing it =P).
I saw your RAW SQL solution and it looked genius-simple. I have short
experience with the JOIN operation but that make sense to me. Yet, I
tested, and I still get
(Carrot, Flavour, 2.0)
and just
(Cars, Smell, 4.2) (Cars, Usability, 4.9)without the other contexts.
If I remove the WHEREs (not filtering by user or thing), it still
presents without nulls (or 0.0)
Is there other way you can see?
Again, thanks
On 6 Dez, 21:48, Ian Clelland <clell...@gmail.com> wrote:
> On Tue, Dec 6, 2011 at 1:35 PM, Reinout van Rees <rein...@vanrees.org>wrote:
>
> > Ah! Now I get your point. You also want the "empty" results for which
> > there's no SQL data. Sorry, but I don't see a way in which you can do that
> > with an SQL query (and so also not with a Django query).
>
> > In case you want all contexts, you'll have to query for those
> > specifically. And afterwards grab the results belonging to that context. So
> > you won't escape a for loop and some manual work, I'm afraid.
>
> Raw SQL:
> select thing, name, vote from mydatabase_votecontext left join
> mydatabase_vote on (mydatabase_vote.context_id = mydatabase_votecontext.id)
> where thing='Carrot' and user='Me'
>
> That should return null if there is no vote. If you'd rather have zeros,
> then use this:
>
> select thing, name, ifnull(vote, 0.0) from mydatabase_votecontext left join
> mydatabase_vote on (mydatabase_vote.context_id = mydatabase_votecontext.id)
> where thing='Carrot' and user='Me'
>
> There still might be a way to do it with the ORM; but you can definitely
> use raw sql for this.
>
> --
> Regards,
> Ian Clelland
> <clell...@gmail.com>

-- 
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