我对Wagtail真的很陌生。我一直在尝试找到一种方法来过滤选择器(PageChooserPanel)中的值。我正在建立一个故事网站,作者可以在其中创建非线性故事。我遵循一个博客模型来构建它并对其进行扩展。我已经到了作者可以通过可订购链接链接页面的地步。问题是其他故事的可订购显示页面。有没有办法过滤掉不相关的页面。我很感激这方面的任何帮助。先感谢您!
这是我的代码:
class StoryPath(models.Model):
route = models.ForeignKey('story.StoryPage', on_delete=models.SET_NULL, null=True, related_name='next_path', verbose_name='Story Path')
panels = [
PageChooserPanel('route', page_type='story.StoryPage'),
FieldPanel('correct'),
]
class Meta:
abstract = True
class StoryPathOrderable(Orderable, StoryPath):
page = ParentalKey('story.StoryPage', on_delete=models.CASCADE, related_name='story_paths')
class StoryPage(Page):
template = 'story/story_page.html'
body = RichTextField()
content_panels = [
FieldPanel('title', heading='Section Title', classname='collapsible'),
FieldPanel('body', classname='collapsible'),
MultiFieldPanel(
[
InlinePanel('story_paths'),
],
heading = 'Story Paths',
classname = 'collapsible'
)
]
parent_page_type =['story.Story']
subpage_types = []
def __str__(self):
return '%s' % (self.title)
class Story(Page):
subtitle = models.CharField(max_length=250, null=True, blank=True)
content_panels = Page.content_panels + [
FieldPanel('subtitle'),
]
subpage_types = ['story.StoryPage']
def __str__(self):
return '%s' % (self.title)
编辑:这是我正在使用的模板:
{% extends "base.html" %}
{% load static wagtailcore_tags %}
{% block body_class %}{{self.title}}{% endblock %}
{% block extra_css %}{% endblock extra_css %}
{% block content %}
<div class="d-flex justify-content-center flex-column">
<div class="fs-3">{{page.title}}</div>
<div>{{page.body|richtext}}</div>
</div>
{% endblock content %}