Thanks for the suggestion, I'm vaguely familiar with lazyness, and I think at the moment my template tag is actually ok. It just returns a queryset of the latest objects for a particular model to the context.
I was just surprised to see debugging output from the template tag when as far as I was aware it shouldn't have been running. As it is the "render" method is the only one which creates a queryset, and as this isn't run, it doesn't really matter. Now you mention it though, the queryset isn't even evaluated by the template tag so the database isn't hit unless I use the variable it returns to the context. Pete On Oct 16, 7:57 pm, Chip Grandits <boulderc...@gmail.com> wrote: > Pete, > I'm not completely familiar with you problem or what exactly > 'get_latest' does. > But my intuition is that you may wish to consider rewriting > 'get_latest' to be more "lazy" > If it is not exactly clear what I mean by that see Django online docs > on lazy querysets > e.g.http://docs.djangoproject.com/en/dev/topics/db/queries/#querysets-are... > > I became a big fan of laziness when I learned Haskell last year. > IMHO laziness is usually a good design consideration. > > Of course this advice might not really apply to your problem - it's > just a suggestion > > -Chip > > On Oct 16, 8:49 am, "pjrhar...@gmail.com" <pjrhar...@gmail.com> wrote: > > > I have some template code which looks something like this: > > {% if condition %} > > {% get_latest parameter1 %} - foo > > {% else %} > > {% get_latest parameter2 %} - bar > > {% endif %} > > > get_latest is a custom template tag, and I noticed that in my > > debugging output it is being run both times - ie with parameter1 and > > parameter2. Since it hits the database I'd rather not have it do > > this. > > > On the other hand only foo or bar appears in the rendered page. I > > guess the template system renders all the tags, then discards > > whichever branch does not apply. > > > So the question is, can I avoid this? Or should I just change my > > template tag so I can call it with: > > {% get_latest condition parameter1 parameter2 %} > > > Thanks, > > > Pete --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---