tejas schrieb:
> Hi - I'm a Django newbie and I have a query that, using the syntax in
> the database API, would become very slow. I'm wondering what the way
> around it is.
> 
> I have 3 tables
> 
> Group -- contains a list of groups
> 
> 
> Item:  (each item belongs to a group)
>     ForeignKey(groupid)
> 
> ItemRatingsByGroup: (the rating for each item from each group)
>     ForeignKey(groupid)
>     ForeignKey(itemid)
>     rating
> 
> So in the ItemRatingsByGroup Table there at most one row for each
> (item, group) combo (some groups may not have rated an item)
> 
> I want to list the items in a group - and also show the rating given
> by that group. Using SQL this would be a left join from Item to
> ItemRatingsByGroup
> 
> 
> But using the Django ORM (not using exact syntax)
> 
> items = Item.objects.get(groupid=desiredgroupid)
> 
> for item in items:
>     ratings =
> item.item_ratings_by_group_set.filter(groupid=desiredgroupid)
>     #there's only 0 or 1 results
>     for rating in ratings:
>       #display the rating with the item
> 
> 
> In the Django ORM case, a new query would seem to be executed to get
> the ratings for each item.
> 
> Is there anything in Django to help me execute this query (I don't
> think select_related works backwards). Also on a related note, how do
> I find out what queries Django is running?
> 
> thanks
> 
>  

http://www.djangoproject.com/documentation/faq/#how-can-i-see-the-raw-sql-queries-django-is-running

here you can see what queries django is running.

mfg Paul Rauch

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

Reply via email to