Django CheckboxSelectMultiple widget adds --------- value to query set
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 t开发者_如何学Gohat and what causes this weird behavior?
both your questions are answered in the documentation: https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ModelChoiceField
精彩评论