get two fields inline in django-crispy forms but not others horizontal?

故事扮演 提交于 2019-12-03 09:45:33

问题


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


回答1:


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'),
    ),
)


来源:https://stackoverflow.com/questions/23021746/get-two-fields-inline-in-django-crispy-forms-but-not-others-horizontal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!