Django Crispy Forms rearrange layout and retain Bootstrap inline formatting?

django, django-crispy-forms, forms, twitter-bootstrap

Solution

Have you tried using the `fields` attribute? The generated Form class will have a form field in the order specified in the fields attribute.

class MyEntryForm(ModelForm):
    class Meta:
        model = "mymodel"
        fields = ['field1', 'field3', 'field2']

Problem

I am currently working on a Django project and am using cripsy-forms to format and display the HTML forms in conjunction with Bootstrap. If I allow Crispy-Forms to use the default layout order, it will (for the most part) format the correct HTML layout to utilize inline forms with Bootstrap. In order to rearrange the order of the fields on the form, I am attempting to utilize the Layout helper. When I add the Layout helper, Crispy-Forms loses it's inline labeling ability and all labels are displayed above their field counterparts. How can I get Crispy Forms to re-order the layout and still retain Bootstrap inline formatting? ``` class MyEntryForm(ModelForm): def __init__(self, *args, **kwargs): super(MyEntryForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_id = 'id-MyEntryForm' self.helper.help_text_inline = True self.helper.error_text_inline = True self.form_show_labels = True self.helper.form_method = 'post' self.helper.form_action = 'submit' self.helper.form_tag = False self.helper.add_input(Submit('submit', 'Submit')) self.helper.form_class = 'form-inline' self.helper.field_template = 'bootstrap3/layout/inline_field.html' self.helper.layout = Layout( 'field1', 'field3', 'field2', ) ```

Original source