Django form field or textarea size or attributes cols, rows, class

Something that can be encountered very often is modification of form via meta of a Model form. This way you can add WYSIWYG, adjust fields in length or adjust completely with CSS.


from page.models import *
from django import forms
from django.forms import ModelForm

class StaticPageForm(ModelForm):
    class Meta:
        model = StaticPage
        fields = ['title', 'raw_text', 'has_copyscape_check']
        widgets = {
            'title': forms.TextInput(attrs={'size': 101}),
            'raw_text': forms.Textarea(attrs={'cols': 100, 'rows': 35}),
            'has_copyscape_check': forms.CheckboxInput(attrs={'class': 'h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500'}),

    def __init__(self, *args, **kwargs):
        super(StaticPageForm, self).__init__(*args, **kwargs)