With rich text editor, editors of the site can write the same as using offfice a beautiful, WYSIWYG page. Here to tinymce, for example, to use other rich text editor is similar.
Installed in a virtual environment:
pip install tinymce
Configure:
Create a model class:
from django.db import models
from tinymce.models import HTMLField # 使用富文本要调用
# Create your models here.
class goods_test(models.Model):
'''测试模型类'''
'''choices第一个元素是database数据,第二个数据是选择框上显示的文字'''
status_choices = (
(0, '下架'),
(1, '上架')
)
'''使用choices,它是一个二元元组或列表,admin后台会是一个选择框,而不是text框'''
status = models.SmallIntegerField(choices=status_choices, verbose_name='商品状态')
detail = HTMLField(verbose_name='商品详情')
class Meta:
db_table = 'test_good' # 如果不指定,数据库自动生成的名字为 应用名_模型类名
verbose_name = '商品'
verbose_name_plural = verbose_name
Registration model classes:
from django.contrib import admin
from link_mysql.models import goods_test
# Register your models here.
admin.site.register(goods_test)
Create an administrator:
python manage.py createsuperuser
Login background management system can be seen: