Control the size TextArea widget look in django admin

后端 未结 1 456
后悔当初
后悔当初 2020-12-28 13:19

I managed to override the look of a TextArea Widget in the django admin interface with two different ways:

using formfield_overrides

in

相关标签:
1条回答
  • 2020-12-28 13:52

    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.

    0 讨论(0)
提交回复
热议问题