Thanks for the answers.  I thought that the view was already pulling
the data.  I didn't realize it gets pulled when called in the
template.  I was able to rewrite the view to provide the data more
efficiently.

I have another related question on the topic of query expense.  What
is the best practice as far as database table design?

I have 3 tables: studio, film, images.  If film has a foreign key to
studio, and images has a foreign key to film.  If I wanted to pull all
of the images for a particular studio, it would be more expensive to
pull:

all films (given studio), and then films.images_set

as opposed to:

including the studio in the image table and then pulling all images
(given studio).

But there is some data replication here.  Technically, I can discover
studio by following the link from image to film to studio.  But it I
need less queries given this particular need.  What is the best
practice in a scenario like this?

On Oct 19, 4:17 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Oct 19, 4:43 pm, Tom Evans <tevans...@googlemail.com> wrote:
>
>
>
>
>
> > On Tue, Oct 19, 2010 at 4:16 PM, Daniel Roseman <dan...@roseman.org.uk> 
> > wrote:
> > > The solution here is to evaluate the queryset in your view first,
> > > before passing it to the template. You can do this by simply calling
> > > list() on it - eg instead of defining your context as {'actor_list':
> > > actor_list}, do {'actor_list': list(actor_list)}. Bear in mind though,
> > > if you're doing things like pagination, this will end up being less
> > > efficient, as it will evaluate the *whole* queryset rather than just
> > > the elements you need for the page you're on.
>
> > I'm 100% sure Daniel is aware of this, but it is good to explicitly
> > point it out: this will also require more memory, as instead of
> > iterating through the queryset and producing one object at a time, it
> > has to create and store a list of objects.
>
> > Cheers
>
> > Tom
>
> Well, to a certain extent. When iterating through a queryset, Django
> populates it in chunks of 100 items. So if the actor_list set is less
> than 100 - which is a pretty good bet seeing as it's not paginated -
> there'll be very little difference in terms of memory consumption.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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