Re: Expense of django query

2010-10-20 Thread Ed
Brilliant. Thanks! On Oct 20, 9:41 am, Javier Guerra Giraldez wrote: > On Wed, Oct 20, 2010 at 7:59 AM, Ed wrote: > > what is the purpose of ifchanged? > > since the images are sorted by film, if you just show the film for > every image it would be repeated.  with {% ifchanged %} it's only > sh

Re: Expense of django query

2010-10-20 Thread Javier Guerra Giraldez
On Wed, Oct 20, 2010 at 7:59 AM, Ed wrote: > what is the purpose of ifchanged? since the images are sorted by film, if you just show the film for every image it would be repeated. with {% ifchanged %} it's only shown before all the images for this film, so the result is like this: film A image

Re: Expense of django query

2010-10-20 Thread Ed
Thanks for the suggestion. Javier's was exactly what I needed. The one question I have is why what is the purpose of ifchanged? I'm aware of the command but I don't see the purpose of it within a loop. On Oct 20, 5:18 am, Daniel Roseman wrote: > On Oct 19, 9:46 pm, Ed wrote: > > > > > > > Th

Re: Expense of django query

2010-10-20 Thread Daniel Roseman
On Oct 19, 9:46 pm, Ed wrote: > 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

Re: Expense of django query

2010-10-19 Thread Javier Guerra Giraldez
On Tue, Oct 19, 2010 at 3:46 PM, Ed wrote: > 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: what i do is: in the view, get

Re: Expense of django query

2010-10-19 Thread Ed
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 practi

Re: Expense of django query

2010-10-19 Thread Daniel Roseman
On Oct 19, 4:43 pm, Tom Evans wrote: > On Tue, Oct 19, 2010 at 4:16 PM, Daniel Roseman 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 {'

Re: Expense of django query

2010-10-19 Thread Tom Evans
On Tue, Oct 19, 2010 at 4:16 PM, Daniel Roseman 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':

Re: Expense of django query

2010-10-19 Thread Daniel Roseman
On Oct 19, 3:45 pm, Ed wrote: > I have a table for Actor that I query and populate the result in > actor_list to pass to the template. I installed the Django Debug > Toolbar to check the queries hitting the database and found some > strange behavior. If I iterate through the actor_list, only one S

Re: Expense of django query

2010-10-19 Thread Javier Guerra Giraldez
On Tue, Oct 19, 2010 at 9:45 AM, Ed wrote: > Why is that?  Is there a way to do this that doesn't result in two > queries? check: http://docs.djangoproject.com/en/1.2/topics/db/optimization/#don-t-overuse-count-and-exists there's a tip about loading the whole query once: use {% with actor_list

Expense of django query

2010-10-19 Thread Ed
I have a table for Actor that I query and populate the result in actor_list to pass to the template. I installed the Django Debug Toolbar to check the queries hitting the database and found some strange behavior. If I iterate through the actor_list, only one SQL query is created, as expected: {% f