get two fields inline in django-crispy forms but n

2020-05-24 04:41发布

I want to have two fields corresponding to check boxes next to next (not one below other) like I have shown in the image.

my form inherits from models.Form and has other fields, which I have left out here. is it possible to get this using crispy-forms? For rest of the fields,

I use self.helper.form_class='form-horizontal', which I want to keep intact for other form fields

Thanks

enter image description here

1条回答
虎瘦雄心在
2楼-- · 2020-05-24 05:33

This is untested but I think this will work.

self.helper.layout = Layout(
    Div(
        Div('inlineField1',css_class='col-md-6',),
        Div('inlineField2',css_class='col-md-6',),
        css_class='row',
    ),
    'other_fields',
    ...,

    FormActions(
        Submit('submit', 'Submit'),
    ),
)
查看更多
登录 后发表回答