Django two-column form

What is the most pythonic way to implement django ModelForm for a 9-field model that will be split into two columns in a template? Something like that:

<form>
    <div class="column-1">
        5 fields for column 1
    </div>
    <div class="column-2">
        4 fields for column 2
    </div>
</form>
+3
source share
2 answers

I think the easiest and cleanest way is to stick with the methods outlined in the docs ...

<form>
    <div class="column-1">
       {{ form.field1 }}
       ...
       {{ form.field5 }}       
    </div>
    <div class="column-2"> 
       {{ form.field6 }}
       ...
       {{ form.field9 }}
       </div>
</form>
+4
source

You can use carljm django-form-utils , which allows you to define fields. You can specify a class for each set of fields as you wish. However, you still have to list all the fields in the form definition.

+1
source

All Articles