首页 > 解决方案 > 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"), 
        ]

标签: djangopython-3.xdjango-modelswagtail

解决方案


您可以使用PageChooserBlock创建StreamField。像这样的东西:

pages = StreamField([
        ('page', blocks.PageChooserBlock())
    ])

推荐阅读