Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Django admin readonly textarea field

In Django admin, if I have a model field that's a TextField and set it as readonly using readonly_fields, then it's displayed as text in a <p> tag.

I'd like it to still be displayed as a textarea field, but with its disabled attribute set.

What's the simplest way to accomplish this?

like image 594
Phil Gyford Avatar asked Jan 28 '26 14:01

Phil Gyford


1 Answers

use a form field

   somefield = forms.CharField(
       widget=forms.TextInput(attrs={'readonly':'readonly'})
    )
like image 54
cinoch Avatar answered Jan 31 '26 09:01

cinoch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!