Thursday, April 8, 2010

Django formset.as_table() displays vertically only

Like other people, I want to be able to display a formset as an ordinary 'horizontal' table, i.e. where all headings are in their own row, separate from the data:
<table>
<thead>
<tr><th>column1</th><th>column2</th></tr>
</thead>
<tbody>
<tr><td>form1.value1</td><td>form1.value2</td></tr>
...
</tbody>
</table>

Whereas the django formset.as_table() method displays as below, with the heading on the same row as the data:
<table>
<tr><th>column1</th><td>form1.value1</td></tr>
<tr><th>column2</th><td>form1.value2</td></tr>
</table>


The solution is a pretty nasty gob of template code, since to fix it you need to make all the error handling and form magic explicit. Django devs: Let's have a new method or parameter to display the formset horizontal rather than vertical.

No comments: