Reputation: 17
I have created the following form:
class ProductFilter(forms.Form):
price = forms.IntegerField(label='Price', widget=forms.Select(choices=PRICE_CHOICES), required=False)
category = forms.ModelChoiceField(queryset=Category.objects.all(), required=False)
language = forms.ModelChoiceField(queryset=ProductLanguage.objects.all(), required=False)
The default <option>
in both category and language is displayed as "------------"
. I know i can set initial="..."
, but I would like the default option to be something that is not part of the queryset.
Is it possibe to insert an option somehow? I don't want to create a language or a category called "all".
Upvotes: 1
Views: 31
Reputation: 308879
You can change the ------------
by setting empty_label
.
category = forms.ModelChoiceField(queryset=Category.objects.all(), required=False, empty_label='(none)')
Note that this value is used when no category is selected. It would be confusing to set empty_label="all"
.
Upvotes: 1