Models
Step 1: Install rich text editor and image resizer
Image resizer
Rich text editor
Install Pillow: pip install pillow. Pillow is a required dependency for ResizedImageField.
Install the django_resized package: pip install django_resized
Add 'django_resized' to your INSTALLED_APPS list in your project's settings.py file:
INSTALLED_APPS = [
...
'django_resized',
...
]
Add the default configuration to the settings.py file:
DJANGORESIZED_DEFAULT_SIZE = [1920, 1080]
DJANGORESIZED_DEFAULT_QUALITY = 75
DJANGORESIZED_DEFAULT_KEEP_META = True
DJANGORESIZED_DEFAULT_FORCE_FORMAT = 'PNG'
DJANGORESIZED_DEFAULT_FORMAT_EXTENSIONS = {'PNG': ".png"}
DJANGORESIZED_DEFAULT_NORMALIZE_ROTATION = True
Import ResizedImageField in mdels.py: from django_resized import ResizedImageField
Run migrations:
python manage.py makemigrations
python manage.py migrate
Install django-tinymce: pip install django-tinymce
Add 'tinymce' to the INSTALLED_APPS:
INSTALLED_APPS = [
...
'tinymce',
...
]
Add the default configuration to the settings.py file:
TINYMCE_DEFAULT_CONFIG = {
'selector': 'textarea',
'toolbar': "undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | fullscreen | fontselect | fontsizeselect | forecolor backcolor | subscript superscript | removeformat | table | hr",
'menubar': True,
'forced_root_block': 'div',
'plugins': 'table hr image link code lists media textcolor wordcount fullscreen emoticons'
}
Import HTMLField in models.py: from tinymce.models import HTMLField
Run migrations:
python manage.py makemigrations
python manage.py migrate
Step 2: Imports
from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils import timezone
from tinymce.models import HTMLField
from django_resized import ResizedImageField
from django.core.validators import FileExtensionValidator
from django.utils.text import slugify
import datetime
Step 3: Models