我正在尝试使用文章到页面结构设置 Wagtail 网站,但我正在努力。例如,一篇评论文章可能有一个介绍页面、一个基准页面和一个结论页面。我想弄清楚如何在 wagtail 中允许这种关系并拥有它,以便编辑可以将多个页面添加到同一页面上的同一篇文章中。我可以想象页面界面看起来有点像你在页面上的内容、推广和设置,但具有添加、重命名和重新排序页面的能力。我尝试在链接到文章的页面模型上使用外键,但我无法以我想要的方式在管理员中显示它。
这是我想要使用的模型布局的 django 版本。您有一篇由一页或多页组成的父文章。这些页面应该是可编辑的、可排序的,并且可以在管理员的一个面板中使用流域创建:
Class Article(models.Model)
STATE_DRAFT = 0
STATE_REVIEW= 1
STATE_PUBLICATION = 2
STATE_HIDDEN = 3
STATE = (
(STATE_DRAFT, 'draft'),
(STATE_REVIEW, 'pending review'),
(STATE_PUBLICATION, 'ready for publication'),
(STATE_HIDDEN, 'hide and ignore'),
)
title = models.CharField(_('title'), max_length=256)
slug = models.SlugField(
_('slug'), unique=True, blank=True, default='', max_length=256
)
description = models.TextField(
_('description'), max_length=256, blank=True, default=''
)
author = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='article'
)
publication = models.DateTimeField(
null=True, blank=True, default=None, db_index=True, help_text='''
What date and time should the article get published
'''
)
state = models.PositiveIntegerField(
default=0, choices=STATE, help_text='What stage is the article at?'
)
featured = models.BooleanField(
default=False,
help_text='Whether or not the article should get featured'
)
class Page(Page):
article = models.ForeignKey(
'Article', on_delete=models.CASCADE, related_name='pages'
)
title = models.CharField(max_length=256)
number = models.PositiveIntegerField(default=1) # So pages are ordered
body = models.TextField(blank=True)
呼啦一阵风
猛跑小猪
相关分类