JackLeo
JackLeo

Reputation: 4740

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 that and what causes this weird behavior?

Upvotes: 2

Views: 3548

Answers (1)

akonsu
akonsu

Reputation: 29576

both your questions are answered in the documentation: https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ModelChoiceField

Upvotes: 4

Related Questions