2

我想将每个复选框变成一个切换按钮。但是,Django 会自动将复选框呈现为列表。我无法将它们分开。

这就是我现在所拥有的:

<div class="column">
    <div id="filters">
        {% for field in filter_form %}
            <div class="filter_category">
                {% for checkbox in field %}
                    {{ checkbox }}
                {% endfor %}
            </div>
        {% endfor %}
    </div>

我想要这样的东西,所以我可以更灵活地做些什么。

<div class="column">
    <div id="filters">
        {% for field in filter_form %}
            <div class="filter_category">
                {% for checkbox in field %}
                    {{ checkbox.label }}{{ checkbox.tag }}
                {% endfor %}
            </div>
        {% endfor %}
    </div>

这是我的表单类,构造函数只是填充每个字段的选项

class Class_filters_form(forms.Form):

    subject_code = forms.CharField(widget=forms.CheckboxSelectMultiple(attrs={"checked": ""}))
    subject_level_CLB = forms.CharField(widget=forms.CheckboxSelectMultiple(attrs={"checked": ""}))
    subject_level_CEFR = forms.CharField(widget=forms.CheckboxSelectMultiple(attrs={"checked": ""}))
    time_start = forms.TimeField(widget=forms.CheckboxSelectMultiple(attrs={"checked": ""}))
    campus = forms.CharField(widget=forms.CheckboxSelectMultiple(choices=Data_room.CAMPUS_CHOICE, attrs={"checked": ""}))

    def __init__(self, *args, **kwargs): ...
4

0 回答 0