views:

304

answers:

1

I am a newbie to Django and web-development in general so be patient for maybe a very dumb question :)

I have a form generated from a model and in this form I have about 20 checkboxes. Now they are aligned in one long column and it looks not very nice from a UI point of view. I'd like this column to be split in several ones but still have this form be automatically generated from the model. What would you suggest me to do?

In the generated HTML individual checkboxes look like this:

<li><label for="id_boxes_0"><input type="checkbox" name="boxes" value="1" id="id_boxes_0" /> some name</label></li>
+2  A: 

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.

Carl Meyer
I think he's struggling with formatting of the CheckBoxSelectMultiple widget.
slypete