How can I change the width of a textarea form element if I used ModelForm to create it?
Here is my product class:
class ProductForm(ModelForm):
l
In the event that you're using an add-on like Grappelli that makes heavy use of styles, you may find that any overridden row and col attributes get ignored because of CSS selectors acting on your widget. This could happen when using zuber's excellent Second or Third approach above.
In this case, simply use the First Approach blended with either the Second or Third Approach by setting a 'style' attribute instead of the 'rows' and 'cols' attributes.
Here's an example modifying init in the Third Approach above:
def __init__(self, *args, **kwargs):
super(ProductForm, self).__init__(*args, **kwargs) # Call to ModelForm constructor
self.fields['short_desc'].widget.attrs['style'] = 'width:400px; height:40px;'
self.fields['long_desc'].widget.attrs['style'] = 'width:800px; height:80px;'