Text Area Widget in Django Admin

Adding widgets to CharField/fields in Django Administrator

Advert

If you use django admin to manage your application and use a CharField with size more than 300 i'm sure you need a Text Area to fill it in, yes in your admin too.

It's just a few additional lines to your forms.py (define a new form with widget) and admin.py ( Inform model admin to use the form).

 # forms.py
class FaqForm(forms.ModelForm):
  answer = forms.CharField( widget=forms.Textarea(attrs={'rows': 5, 'cols': 100}))
  class Meta:
    model = Faq
    fields = ('__all__')

That my custom form with Textarea widget attached to answers field which is a CharFIeld.

#admin.py
class FaqsAdmin(admin.ModelAdmin):
  list_display = ['id', 'question', 'status']
  form = FaqForm

You got yourself a text area in your admin.

Comments

Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ rel="nofollow" for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.

Last 5 Articles

All Articles >

  1. Domain Authority

     
  2. Public Endpoint in Django Rest Framework

     
  3. 4 Ways to Increase Conversion Rates using Videos

     
  4. Getting the best customer experience analytics solutions

     
  5. How to Remove an App from Django Project

     

News Letter

Subscribe to our email newsletter for useful tips and valuable resources, sent out every new article release.