Hi Mark,

On 07/24/2011 10:15 AM, Marc Aymerich wrote:
> 
> 
> On Sun, Jul 24, 2011 at 3:10 AM, Gelonida N <gelon...@gmail.com
> <mailto:gelon...@gmail.com>> wrote:
> 
>     Hi,
> 
>     I try to populate a template from a Model with a ForeignKey element)
>     members of the foreign key element should be displayed.
> 
>     If I understand correctly my first attempt resulted in one query for
>     fetching the entries from my first model and in one Query for each row
>     in order to look up the contents related to the foreign key.
> 
> 
> Hi, you can use select_related in order to prefetch related data.
> https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related
> 
 This solved my issue and transformed my multiple  queries into one
query with a join statement.

It is interesting to know however, that with my real code.
(slightly more complex models)
Song.objects.all()select_related()
did not have the desired effect.

I had to specify which foreign key to follow to make it work
so I had to use
Song.objects.all()select_related('composer')

Thanks again for the fast help

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