# 导入所需模块
from django.db import models
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.images.models import Image
from wagtail.images.edit_handlers import ImageChooserPanel
# 创建自定义页面模型
class BlogPage(Page):
# 定义模型字段
author = models.CharField(max_length=100)
date = models.DateTimeField(auto_now_add=True)
body = RichTextField()
header_image = models.ForeignKey(
Image,
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
# 定义编辑界面的字段布局
content_panels = Page.content_panels + [
FieldPanel('author'),
FieldPanel('date'),
FieldPanel('body'),
ImageChooserPanel('header_image'),
]
原创文章,作者:guozi,如若转载,请注明出处:https://www.sudun.com/ask/89806.html