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)
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"
)
- [Answer]-Django 1.7 – update a user record using a form
- [Answer]-Django using timedelta to filter results in template
Source:stackexchange.com