On 1/29/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > On 1/29/06, Roberto Aguilar <[EMAIL PROTECTED]> wrote: > > is there a way to say something like: > > > > {% set blurb entry.get_blurb %} > > > > and then just use: > > > > {{ blurb.get_author.username }} > > {{ blurb.subject }} > > {{ blurb.text }} > > > > It looks like having to use get_blurb every time is expensive since > > the object is being retrieved multiple times (not to mention more > > typing ;). Is setting variables inside templates against the way of > > the template? > > Hi Berto, > > Behind the scenes, get_blurb() only hits the database once. It caches > the result for subsequent accesses. There's no way to set variables in > the template language, but if you're wanting to save on typing, I'd > recommend passing 'blurb' as a variable in your template's context.
I was thinking about that, but it doesn't exactly work out if, for example, I have a list of journal entries being sent to a template. It doesn't make sense to me to create a list of blurbs and pass it to the template rather than just using get_blurb when i need the blurb info. Along the same lines, I'm creating a form to edit a journal entry. I have found myself passing in journal_form and blurb_form objects to a template in order to render the input form for a user to edit. Is this the right approach or am I missing how to get a foreign key object's fields in a form? Thanks for the response! -berto.