change a widget attribute的兩種方法,一種是在__init__方法裡,
一種是在class Meta裡
class PaymentForm(ModelForm):
#def __init__(self, *args, **kwargs):
# super(PaymentForm, self).__init__(*args, **kwargs)
#
# # change a widget attribute:
# self.fields['pay_date'].widget.attrs["class"] = "date-pick"
class Meta:
model = Payment
widgets = {
'pay_date': TextInput(attrs={'class': "date-pick"}),
}