问题描述
我有一个CheckBoxSelectMultiple
表单字段,我使用InlineCheckBoxes
中的crispy-forms
使所有这些复选框都内联。由于我没有图像,因此我将使用代码片段作为示例。
这就是我想要的表单在html中的样子,我将使用stars
而不是框
*name1 *name2 *name3 *name4
*name5 *name6 *name7 *name8
*name9 *name10 *name11 *name13
我该怎么做才能在每行之间添加更多空间并使其垂直对齐(如上图所示)?
这是我的表格。py
class AttendanceForm(forms.ModelForm):
class Meta:
model = Attendance
fields = ['student',]
widgets = {'student': forms.CheckBoxSelectMultiple()}
def __init__(self,class_pk,current_user,*args,**kwargs):
super(AttendanceForm,self).__init__(*args,**kwargs)
current_student = Class.objects.get(id=class_pk)
self.helper = FormHelper(self)
self.fields['student'].queryset = current_student.student.order_by('first_name')
self.helper.layout = Layout(
InlineCheckBoxes('student')
)
我当前的html。 (它未如上图所示完全对齐!)
<form method="POST" class="ml-auto mr-auto">
{% csrf_token %}
<div style="text-align: justify;">{% crispy form form.helper %}</div>
<button
type="submit"
class="btn btn-success btn-sm"
style="font-size: 15px"
>
Check
</button>
</form>
先谢谢!
解决方法
现在,我要做的就是使所有元素内联显示,并在每行多于一行的位置添加空格。因此,我不需要为此使用酥脆的形式。我从模板和表单类中删除了所有香脆的表单标签,然后在模板中我要做的就是:
imshow('predictions.jpg')