pythondjangodjango-modelsdjango-model-field

Empty label in widget Select


Here in Forms we can use the empty_label. I use widget Select, my choices are from database, does it possible to use here empty_label? In model I have:

position = forms.IntegerField(label=position_label, required=False, 
    widget=forms.Select(choices=Position.objects.all().values_list('id', 'position'),
    attrs={'class':'main', 'title': position_label},
    ), empty_label="(Empty)")

But the error is:

TypeError: __init__() got an unexpected keyword argument 'empty_label'

How to set the label to 'Empty'?


Solution

  • empty_label is a property of the field, not the widget. You already have a label set for position.