Login

Making a django inline (model) formset really tabular

Author:
fnl
Posted:
April 15, 2009
Language:
HTML/template
Version:
Not specified
Tags:
template form modelform formset inline
Score:
5 (after 5 ratings)

As there is no straight way to re-produce the real tabular inline formsets you get in django-admin, here is how this template has to look like if you do it form your own formsets generated from formset factories.

 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. InlineFormset Template by petry 6 years, 7 months ago
  2. Printing inline formsets as UL / P by ikke 5 years, 10 months ago
  3. Embedded inline formsets in ModelForm by stan 4 years, 8 months ago
  4. Handles Inline Formsets and also "in-standard-way" normal forms by sebnapi 3 years, 4 months ago
  5. Form with Two InlineFormSets by maeck 6 years, 6 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 ?

#

Please login first before commenting.