Question

I am working on a project using Bootstrap and making use of Class Based Views. The forms that are rendered automagically are quite nice. But I want to make one simple change. Given a model that has city, state & zip fields, I want the form to render all three off those fields on the same row.

Name [                                    ]
Addr [                                    ]
City [        ]  State [  ]   Zip [       ]  <-- 3 fields, 1 row

I assume this is a pretty common task that has an elegant solution, but I have not found it. I was hoping django-crispyforms Row('city', 'state', 'zip'), would do in the Layout but that did not work.

Was it helpful?

Solution

I haven't used crispy forms in a while but I believe with bootstrap you have to do something like example below because you cannot simply insert form elements into a row:

Row(
  Div('city', css_class='span4'),
  Div('state', css_class='span4'),
  Div('zip', css_class='span4')
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top