title: Django templates: loop through and print all available properties of an object?
body: <p>I have a database object called <code>manor_stats</code>, with around 30 fields. For most rows, most of these fields will be null. </p>
  
  <p>In my template, I'd like to loop through all the fields in the row, and print info for only the fields that aren't null. </p>
  
  <p>For example, there's a field called "name": I'd like to print <code>&lt;li&gt;Name: {{ manor_stats.name }}&lt;/li&gt;</code> in the template ONLY for those objects where the field isn't null. Ideally I'd like to pull in "Name: " from somewhere automatically too, rather than specifying it.</p>
  
  <p>I know I could use <code>{% if manor_stats.name %}</code> to check whether each field is null, but I don't want to do that 30 times for all the fields. </p>
  
  <p>Here's what I have in views.py:</p>
  
  <pre><code>manor_stats = Manors.objects.get(idx=id)
  return render_to_response('place.html', { 'place' : place, 'manor_stats' : manor_stats }, context_instance = RequestContext(request))
  </code></pre>
  
  <p>And then in place.html, I'd like to have something that works approximately like this (pseudocode, with ??? indicating the bits that I don't know how to do):</p>
  
  <pre><code>{% if manor_stats %} 
  &lt;ul&gt;
   {% for manor_stats.property??? in manor_stats %} 
    {% if manor_stats.property %} 
     &lt;li&gt;{{ manor_stats.property.field_name??? }} {{ manor_stats.property.value??? }}&lt;/li&gt;
    {% endif %}
   {% endfor %
  {% endif %}
  </code></pre>
  
  <p>Hope that makes sense...</p>