I'm trying to access the body text of a child page in my Django / Wagtail CMS blog. I can return the child page title, but I don't know how to use that to get the rest of the child page attributes. The parent is IndexPage, and the child is IndexListSubPage. My model is:
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'),
]
I have tried various combinations in my template:
{{ sub_pages }} //returns <QuerySet [<Page: Page title here>]>
{{ sub_pages.body }} //returns nothing
This returns the page title for the child page, but I also want other attributes, like the body text. Any ideas? I have tried the image template settings from here as well - again, I can get the title, but no attributes. The page has both image and body text in the admin interface.
self.get_children()
toself.get_children().specific()
to solve this - are you sure this doesn't work? – gasman