title: Django template: check for empty query set
body: <p>Is there a way to check for an empty query set in the Django template? In the example below, I only want the NOTES header to be displayed if there are notes. </p>
  
  <p>If I put an {% empty %} inside the "for" then it does display whatever is inside the empty tag, so it knows it's empty.</p>
  
  <p>I'm hoping for something that does not involve running the query twice.</p>
  
  <pre><code>{% if notes - want something here that works %}
       NOTES:
       {% for note in notes %}
           {{note.text}}  
       {% endfor  %}
  {% endif  %}
  </code></pre>
  
  <p>Clarification: the above example "if notes" does not work - it still displays the header even with an empty query set.</p>
  
  <p>Here's a simplified version of the view</p>
  
  <pre><code>sql = "select * from app_notes, app_trips where"
  notes = trip_notes.objects.raw(sql,(user_id,))
  
  return render_to_response(template, {"notes":notes},context_instance=RequestContext(request))  
  </code></pre>
  
  <p>Edit: the view select selects from multiple tables.</p>