title: What is the current (as of 1.8) most efficient way to reuse a variable that results in database queries in a Django app?
body: <p>I know of <code>with</code>, and I know you can write your own template tags for this purpose, altering the context variable. However, given these circumstances:</p>
  
  <ul>
  <li>Cannot alter an application you are reusing, and do not want to "monkeypatch" its views.</li>
  <li>You have multiple isolated blocks in a given template, whatever.html, and, say, a <code>blog_post</code> context variable that has a <code>categories</code> member. You reference this '<code>categories</code>' field multiple times in the template differently, for instance, you only want the first element in one place/<code>block</code>, and then you iterate them all in a different spot in the template.</li>
  <li>You want to avoid duplicating queries altogether.</li>
  <li>You do not want to enclose everything with a '<code>with</code>'/'<code>endwith</code>' block.</li>
  </ul>
  
  <p>What would be the most efficient way to go about this?</p>