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