Mike
Mike

Reputation: 496

MultipleChoiceField on multiple columns

I have a form in django:

    country=forms.MultipleChoiceField(choices=lista_tari, widget=forms.CheckboxSelectMultiple(),required=True)

What i want is to display this form on multiple columns in the webpage. There are 30 choices, i want them on 6 or 5 or whatever columns.

This is the search.html:

{% block content%}

    <form method="POST" class="post-form">{% csrf_token %}
            {{ form.as_p }}
            <button type="submit" class="save btn btn-default">Save</button>
    </form>


{% endblock %}

I am brand-new to css, html and even django so any help would be of great help. Thank you!

Upvotes: 0

Views: 910

Answers (2)

doru
doru

Reputation: 9110

<form method="POST" class="post-form">{% csrf_token %}
     <div class="form-check form-check-inline">
        {% for field in form %}             
            {% if forloop.counter|divisibleby:3 %}</div><div class="form-check form-check-inline">{% endif %}
                {{ field.errors }}
                {{ field.label_tag }} {{ field }}            
        {% endfor %}
     </div>          
      <button type="submit" class="save btn btn-default">Save</button>
</form>

But probably you should use django-bootstrap3 which helps you to integrate django and bootstrap.

Upvotes: 0

Exprator
Exprator

Reputation: 27533

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

you can try something like this

Upvotes: 1

Related Questions