Which django widget must be used for a dropdown list? I already have a model which provides a dropdown list. It is, however, necessary to customize the corresponding form element (text and error msg text) and it becomes necessary to specify the widget.
Here is the Model:
class ClientDetails(models.Model):
paymentType = models.CharField(max_length=4, verbose_name='Zahlungsart', choices=PAYMENT_TYPES)
And the Form:
class ClientDetailsForm(ModelForm):
paymentType = forms.???(label='Zahlungsart', error_messages={'required': (u'Waehlen Sie die Zahlungsart!'), 'invalid': (u'Waehlen Sie die Zahlungsart!')})
We need to use forms.Select()
class Meta:
model=someForm
fields=['Dropdown']
widgets = {
'Dropdown': forms.Select(attrs={'id':'choicewa'}),
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With