vendredi 28 février 2020

Django form: How to check only one checkbox?

I have a really simple form:

forms.py

OPTIONS = (
    ("B", "Black"),
    ("Y", "Yellow"),
    ("R", "Red"),
)
colors = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                                   choices=OPTIONS)

Is it possible to check only one of these checkbox?

I manage to check all of them

attrs = {"checked": True}
colors = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(attrs=attrs),
                                   choices=OPTIONS)

But I would like to be able to check "Black" and not the two other.

Thank you.

(Django==2.0.7)

Fred




Aucun commentaire:

Enregistrer un commentaire