Django CheckboxSelectMultiple widget adds ------—

2019-07-14 15:51发布

I have form with such field:

categories = forms.ModelChoiceField(
        queryset=Field.objects.all(),                       
        widget=CheckboxSelectMultiple, 
        required=False
    )

And after rendering I get my first value as shown:

<ul>
    <li>
        <label for="id_categories_0"><input type="checkbox" name="categories" id="id_categories_0">---------</label>
    </li>
...

Yes, I don't have Field Model "------". Is it trying to set possible empty value? (same '-------' are used in select boxes to show empty value in the django admin layer).

Sure changing "----------" to "All fields" would be useful (since i will need such option), but how should i achieve that and what causes this weird behavior?

1条回答
Emotional °昔
2楼-- · 2019-07-14 16:08
登录 后发表回答