Friend, it is very easy to get what you want, the only thing is that it is not part of any widget, but a special attribute of the ModelChoiceField model, which is a Field ( django.forms.fields.Field
), so you must know how to set it properly. Being a special attribute of ModelChoiceField, it means that it will only work in fields that are relationships with other models, like this:
class Formulario(forms.ModelForm):
empty_label_message = 'Este seria mi placeholder para un select'
relation_2 = forms.ModelChoiceField(
queryset=MyOtherModel.objects.all(), empty_label=empty_label_message)
class Meta:
model = MyModel
fields = ('name', 'relation_1', )
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['relation_1'].empty_label = empty_label_message
Those would be two of the possible ways to add your 'Placeholder' to a select in django.
Any questions, comments.