Making a django inline (model) formset really tabular

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{{ formset.non_form_errors.as_ul }}
<table id="formset" class="form">
{% for form in formset.forms %}
  {% if forloop.first %}
  <thead><tr>
    {% for field in form.visible_fields %}
    <th>{{ field.label|capfirst }}</th>
    {% endfor %}
  </tr></thead>
  {% endif %}
  <tr class="{% cycle row1,row2 %}">
  {% for field in form.visible_fields %}
    <td>
    {# Include the hidden fields in the form #}
    {% if forloop.first %}
      {% for hidden in form.hidden_fields %}
      {{ hidden }}
      {% endfor %}
    {% endif %}
      {{ field.errors.as_ul }}
      {{ field }}
    </td>
  {% endfor %}
  </tr>
{% endfor %}
</table>

More like this

  1. Printing inline formsets as UL / P by ikke 3 years, 8 months ago
  2. InlineFormset Template by petry 4 years, 6 months ago
  3. GeoDjango maps in admin TabularInlines by alanB 2 years, 7 months ago
  4. Arbitrary length formset by Rupe 3 years, 8 months ago
  5. Form with Two InlineFormSets by maeck 4 years, 5 months ago

Comments

falken (on May 7, 2009):

very nice! it helps me a lot - to be complete, you forgot only {{ formset.management_form }} on top of it

#

ogai (on January 18, 2011):

what about form.non_field_errors for each of the forms in the formset ?

#

(Forgotten your password?)