django - Django Model-有没有办法在 wagtail 面板中选择多个页面,如 checbox?
问题描述
如何在 wagtail 中选择多个页面而不是单个页面?
在我的代码中,我使用 了只选择一页 的link_page
class Collections(models.Model):
heading = TextField(blank=True,)
description = RichTextField(blank=True,)
SelectResources = SortedManyToManyField(SelectResource)
link_page = models.ForeignKey(
'wagtailcore.Page',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
panels = [
FieldPanel('heading', classname="title"),
FieldPanel('description', classname="full"),
FieldPanel('link_page'),
]
class Meta:
abstract = True
class HomeCollections(Orderable, Collections):
page = ParentalKey('Home', related_name='collections')
集合作为内联面板添加到主页
class Home(AbstractForm):
content_panels = AbstractForm.content_panels +[
InlinePanel('collections', label="collections"),
]
解决方案
您可以使用PageChooserBlock创建StreamField。像这样的东西:
pages = StreamField([
('page', blocks.PageChooserBlock())
])
推荐阅读
- php - php mysqli 获取对象
- python - 如何在python中将列表列表转换为数据框
- c++ - 尝试使用自定义类的向量引用已删除的函数 vector.erase
- javascript - 在 javascript 开发过程中如何不毫无意义地重建依赖关系?
- python - 如果 Scrapy Spider 已经在运行,则阻止它启动
- ios - 为什么添加注释时地图视图会放大?
- jquery - 无特殊原因添加了两次课程
- java - 如何在 netbeans 的项目中导入库?
- java - java中List接口是如何存储数据的?
- javascript - p5.js - 一些基本动画的低 FPS