[Answer]-Display "Choose Option" label in Django ModelForm ChoiceField

1👍

Just use the label argument, like:

self.fields['exercise'] = forms.ChoiceField(choices=exercise_choices, label="Choose option")

Or if you would like it present inside the dropdown without being an actual choice then insert it as the first option:

exercises = Exercise.objects.all().order_by('name')
exercise_choices = [(exercise.youtube_id, exercise.name) for exercise in exercises]
exercise_choices.insert(0, (u"", u"Choose option"))
self.fields['exercise'] = forms.ChoiceField(choices=exercise_choices)
👤arocks

0👍

Try empty_label="Choose option" in your forms.py:

class UserForm(forms.Form):
    brand = forms.ModelChoiceField(
        queryset=Brands.objects.all(), required=False, empty_label="Brands"
    )

Leave a comment