Python Wagtail:创建新页面时是否可以将父页面传递给structblock?
我正在创建一个需要多种语言的网站。对于大多数页面,这不是问题,因为我们只是复制页面树。然而,有些组件(比如ModelAdmin,还有一些以类似方式使用的页面)不能以这种方式进行翻译 我有几个StructBlock引用了这样的模型,下面是一个:Python Wagtail:创建新页面时是否可以将父页面传递给structblock?,python,django,wagtail,headless,Python,Django,Wagtail,Headless,我正在创建一个需要多种语言的网站。对于大多数页面,这不是问题,因为我们只是复制页面树。然而,有些组件(比如ModelAdmin,还有一些以类似方式使用的页面)不能以这种方式进行翻译 我有几个StructBlock引用了这样的模型,下面是一个: class StoriesSection(blocks.StructBlock): sub_title = blocks.CharBlock(required=True, help_text='Sub-title displayed at the
class StoriesSection(blocks.StructBlock):
sub_title = blocks.CharBlock(required=True, help_text='Sub-title displayed at the very top')
stories = blocks.ListBlock(
blocks.StructBlock(
[
('image', APIImageChooserBlock(required=True)),
('cta_copy', blocks.CharBlock(required=True, default='Read the article')),
('story', blocks.ChoiceBlock(required=True, choices=get_stories, help_text='Linked story')),
]
)
)
现在,我可以像现在一样使用get_stories方法传递所有故事:
def get_stories():
# use get model to prevent circular import (pages.models <-> streams.blocks)
model = apps.get_model('pages', 'StoryPage')
return [(story.id, story.title) for story in model.objects.all()]
def get_stories():
#使用get model防止循环导入(pages.models streams.blocks)
model=apps.get_model('pages','StoryPage')
为model.objects.all()中的故事返回[(story.id,story.title)]
问题是一个故事有一种特定的语言。创建新页面时,我只希望在“故事”字段中显示与父页面语言匹配的故事。
在这种情况下,即:
/en/
/stories/
/story-1/ <- would like to only pass story pages that are in here
/some-other-page/ <- creating this page
/fr/
/stories/
/a-french-story/
...
/en/
/故事/
/故事一/