[Answered ]-How to organize checkboxes in several columns in Django forms

2👍

You don’t need to change anything in Python code, but you’ll need to layout the form in the template instead of using {{ form.as_ul }}. You can iterate over the form to get the fields. For the simplest possible approach, something like the following could put twenty fields in two columns of ten:

{% for field in form %}
  {% ifequal forloop.counter 11 %}</ul><ul>{% endifequal %}
  <li>{{ field }}</li>
{% endfor %}

Personally I never use the as_* helper methods in real code, as far as I’m concerned they’re only useful for rough prototyping.

Leave a comment