【发布时间】:2019-10-03 15:06:20
【问题描述】:
我正在尝试使用文章到页面结构设置 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)
【问题讨论】:
-
你能分享一些你的代码吗?
Article也是Page的子类吗?还是其他类? -
@NicoGriffioen 我已经添加了我想要的模型布局的代码 sn-p。或许你能从中理解。
-
我很难理解您在这里想要实现的目标。基本上你所说的是,一个页面链接到一篇文章,一篇文章可以显示多个页面。但是这篇文章在您的 Wagtail 中的作用是什么?你到底想达到什么目的,为什么不让 Article 成为 Wagtail 的默认页面的子类?
-
@NicoGriffioen 本质上,Article 类不包含任何内容。它只有关于文章的元数据,例如标题、sn-p 和缩略图。这是列表视图和 RSS 提要中显示的信息。页面模型是每个页面的内容与一个数字一起存储的地方,因此页面是有序的,还有一个标题。这是一个实现的例子。 techradar.com/uk/reviews/huawei-p30-pro。看看他们是如何拥有一篇有 5 页的基础文章
-
老实说,听起来您打算重新发明 Wagtail 的许多本机功能集(从管理 UI 到发布工作流程,一直到页面树的整个概念)到你完成的时候,Wagtail 剩下的就很少了。最终,我认为您将不得不在某些架构上做出妥协以支持更接近 Wagtail 模型的东西,或者实施定制的 Django CMS。