4π
Iβd do this with a django form with one field per line on your grid, with a ChoiceField and RadioSelect as widget:
line1 = forms.ChoiceField(widget=forms.RadioSelect, choices=TRUC)
line2 = β¦
Then you need to find the template layout to render this correctly. RadioSelect
generates a <ul>
with eahc choice being a <li>
. The choice label is included in the <li>
, which is not what you want here.
With floppyforms you could subclass RadioSelect
and give it a cutom template_name (look at the floppyforms/radio.html
template) to omit the labels. You can also alter it to render, say, table cells (<td>
s) instead of <li>
, and make your form markup generate a table with the labels in the tableβs header.
import floppyforms as forms
class RadioSelect(forms.RadioSelect):
template_name = 'myforms/radio.html'
Put your desired row markup in the above template.
Then, in the template that renders your form:
<form method="post" action="youraction">
<table>
<thead>
<td> <!-- put your form headers here --> </td>
</thead>
<tbody>
{% for field in form %}
<tr>
<td>{{ field.label_tag }}</td>
{{ field }}
</tr>
{% endfor %}
</tbody>
</table>
<!-- submit button -->
</form>
Then itβs only a matter of applying a couple of CSS styles to get the layout you need π
- [Django]-Django async update a single page template
- [Django]-Single django app to use multiple sqlite3 files for database
- [Django]-Django: Testing if the template is inheriting the correct template
- [Django]-Resource temporarily unavailable: mod_wsgi (pid=28433): Unable to connect to WSGI daemon process
- [Django]-How to custom checkbox and radio in Django using Bootstrap?