[Django]-Control the size TextArea widget look in django admin

54👍

✅

This is a browser-specific problem.

According to the thread Height of textarea does not match the rows in Firefox:

Firefox always adds an extra line after the textfield. If you want it
to have a constant height, use CSS …

You can set a style attribute of the textarea:

from django.db import models
from django.forms import Textarea

class RulesAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': Textarea(
                           attrs={'rows': 1,
                                  'cols': 40,
                                  'style': 'height: 1em;'})},
    }

Works for me – tested on Firefox v. 23 and Chrome v. 29.

Hope that helps.

Leave a comment