Django:如何在CheckboxSelectMultiple中单独访问标签和复选框?

时间:2013-04-04 22:03:40

标签: html django

我想将每个复选框都设为切换按钮。但是,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): ...

0 个答案:

没有答案