複数の言語で利用できるようにする必要がある Web サイトを作成しています。ほとんどのページでは、ページ ツリーを複製するだけなので、これは問題になりません。ただし、一部のコンポーネント (ModelAdmin だけでなく、同様の方法で使用されるページも考えてください) は、この方法で変換することはできません。
このようなモデルを参照する structblock がいくつかあります。
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()]
問題は、ストーリーに特定の言語があることです。新しいページを作成するとき、親ページの言語に一致するストーリーのみを「ストーリー」フィールドに表示したいと考えています。この場合、それは次のとおりです。
/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/
...
get_stories メソッドに正しい言語を取得する方法はありますか? ヘッドレスセットアップを使用しています