Using formfield_overrides to change textarea size in admin.TabularInline Form in Django

Viewed 5699

TextField size is overridden using formfield_overrides:

from django.forms import Textarea, TextInput 

formfield_overrides = {
    models.TextField: {'widget': Textarea(attrs={'rows':2, 'cols':25})},
}    

This works on the parent form TextFields. Any related child model rendered using admin.TabularInline still shows TextArea with default size.

Notes TextArea in the main Model and Inline related Model

Notes TextArea in main Model and Inline related Model

Is there a way to change TextArea size of TextField of model rendered using admin.TabularInline class?

2 Answers

Yes, just use the same code in the corresponding Inline class,

Admin.py

YourInline(admin.TabularInline):

    formfield_overrides = {
        models.TextField: {'widget': Textarea(attrs={'rows':2, 'cols':25})},
    }    
          ...

You could just assign your model as text fields

strategy_description = models.TextField(null=False, blank=False, max_length=250)
cost_driver_description = models.TextField(null=False, blank=False, max_length=250)

enter image description here

Related