Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django widget for a dropdown list

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!')})
like image 692
paweloque Avatar asked Oct 27 '25 04:10

paweloque


1 Answers

We need to use forms.Select()

class Meta:
    model=someForm
    fields=['Dropdown']
    widgets = {
      'Dropdown': forms.Select(attrs={'id':'choicewa'}),
      }
like image 188
MbeforeL Avatar answered Oct 30 '25 03:10

MbeforeL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!