0
私のDjango/Wagtail CMSブログの子ページの本文にアクセスしようとしています。私は子ページのタイトルを返すことができますが、それを使って残りの子ページ属性を取得する方法はわかりません。親はIndexPageで、子はIndexListSubPageです。Django/WagtailCMS - get_contextを使用して子ページの属性(本文など)を取得します。
{{ sub_pages }} //returns <QuerySet [<Page: Page title here>]>
{{ sub_pages.body }} //returns nothing
これは、子ページのページタイトルを返しますが、私はまた、本文のような他の属性を、したい:私は私のテンプレートで様々な組み合わせを試してみました
class IndexPage(Page):
body = RichTextField(blank=True)
feed_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
ImageChooserPanel('feed_image'),
]
def get_context(self, request):
context = super(IndexPage, self).get_context(request)
context['sub_pages'] = self.get_children()
return context
class IndexListSubPage(Page):
body = RichTextField(blank=True)
feed_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
ImageChooserPanel('feed_image'),
]
:私のモデルがあります。何か案は?私はhereから画像テンプレートの設定を試しました - 再び、私はタイトルを得ることができますが、属性はありません。ページには、管理インターフェースにイメージと本文の両方のテキストがあります。
[Wagtail:親ページ内の子ページのリストを表示](http://stackoverflow.com/questions/32429113/wagtail-display-a-list-of-child-pages-inside-a) -parent-page) – gasman
私はその質問で解決策を試しました - タイトル以外の属性は取得できません。 – geonaut
これを解決するために 'self.get_children()'を 'self.get_children()。specific()'に変更することを期待しています。 – gasman