Declarative definition of widgets in a ModelForm
Say goodbye to the previous and tedious way to define a widget in a model form:
class FooForm(forms.ModelForm):def __init__(self, *args, **kwargs):
super(FooForm, self).__init__(*args, **kwargs)
self.fields['description'].widget = Textarea(attrs={'cols': 80,
'rows': 20}) Now, after [12194] commit is easier and cleaner, without having to redefine the __init__ method: class FooForm(forms.ModelForm):
class Meta:
widgets = {
'description': Textarea(attrs={'cols': 80, 'rows': 20}),
}