Reputation: 2546
I am trying to set a widget for a field in a ModelForm. I'd like to set it in the class Meta
section with the other overrides but this doesn't seem to work:
class Meta:
model = Client
fields = ['name',]
widget = {
'name': forms.TextInput(attrs={
'class': u'form-control'})
}
Only this works:
name = forms.CharField(widget=forms.TextInput(attrs={
'class': u'form-control'}))
class Meta:
model = Client
fields = ['name',]
Other overrides, like labels, error_messages etc. all work when specificed in the Meta class.
How should I define a wdiget in the Meta class to get it working as above.
Upvotes: 0
Views: 2060
Reputation: 7450
You forgot an 's' (its widgets not widget), also you don't need forms.Widget, just Widget.
class Meta:
model = Client
fields = ('name',)
widgets = {
'name': TextInput(attrs={
'class': u'form-control'})
}
Upvotes: 2