开发者

Django CheckboxSelectMultiple widget adds --------- value to query set

开发者 https://www.devze.com 2023-03-31 13:42 出处:网络
I have form with such field: categories = forms.ModelChoiceField( queryset=Field.objects.all(), widget=CheckboxSelectMultiple,

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

0

精彩评论

暂无评论...
验证码 换一张
取 消