RichTextField – Django Models
RichTextField is generally used for storing paragraphs that can store any type of data. Rich text is the text that is formatted with common formatting options, such as bold, italics, images, URLs that are unavailable with plain text.
Django Model RichTextField Explanation
Illustration of RichTextField using an Example. Consider a project named geeksforgeeks having an app named geeks.
Refer to the following articles to check how to create a project and an app in Django.
Now install django-ckeditor package by entering the following command in your terminal or command prompt.
pip install django-ckeditor
Go to settings.py and add the ckeditor and the geeks app to INSTALLED_APPS
Enter the following code into the models.py file of the geeks app.
Now when we run makemigrations command from the terminal,
python manage.py makemigrations
A new folder named migrations would be created in geeks directory with a file named 0001_initial.py
python manage.py migrate
Thus, a geeks_field RichTextField is created when you run migrations on the project. It is a field to store large data. Go to admin.py and register your model.
How to use RichTextField ?
RichTextField is used for storing large data of different types(images, URLs, bold text, etc) in the database. Now let’s check it in the admin server. Whenever we click on Add Geeks Model we can see a RichTextField
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course