How to change the appearance of the TextField in the Django admin?
I want to increase the size of the text area in django admin form.
html_content = models.TextField()
Use the formfield_overrides
attribute in your ModelAdmin class to specify a widget for all TextField instances. For example,
class HtmlModuleAdmin(admin.ModelAdmin):
list_display = ('description', 'enabled')
formfield_overrides = {
models.TextField: {'widget': forms.Textarea(attrs={'rows': 50, 'cols': 150})},
}
admin.site.register(HtmlModule, HtmlModuleAdmin)
However, this will affect all TextField inputs for this particular model in the admin.
You can plug this into a ModelForm
and then use that form in the admin, like:
class HtmlModuleForm(forms.ModelForm):
class Meta:
model = HtmlModule
fields = '__all__'
widgets = {
'html_content': forms.Textarea(attrs={'rows': 50, 'cols': 150})
}
and plug this in in the ModelAdmin
:
class HtmlModuleAdmin(admin.ModelAdmin):
form = HtmlModuleForm
admin.site.register(HtmlModule, HtmlModuleAdmin)