I have a Django/Wagtail/Puput site with this structure:
RootPage
|
|- BlogPage (Puput)
|- InformationPage
I'm trying to display summary info from the Puput blog on the InformationPage. This works with this code, as long as I only have one BlogPage:
class InformationPage(Page):
body = RichTextField(verbose_name=_("body"))
. . .
def get_context(self, request, *args, **kwargs):
context = super(InformationPage, self).get_context(
request, *args, **kwargs)
context['blog_page'] = BlogPage.objects.first()
context['information_page'] = self
return context
But I'm trying to make it work with more than one blog page. It seems like this should work:
class InformationPage(Page):
body = RichTextField(verbose_name=_("body"))
blog_page = models.ForeignKey('wagtailcore.Page', on_delete=models.PROTECT, related_name="information_blog")
content_panels = [
MultiFieldPanel(
[
FieldPanel("title", classname="title"),
FieldPanel("body", classname="full"),
PageChooserPanel('blog_page'),
],
heading=_("Content"),
)]
def get_context(self, request, *args, **kwargs):
context = super(InformationPage, self).get_context(
request, *args, **kwargs)
context['blog_page'] = self.blog_page
context['information_page'] = self
return context
But it doesn't. This was suggested by @gasman here. In other words, if I refer to the blog page properties using context['blog_page'] = BlogPage.objects.first()
, everything works fine, but switching it out to use context['blog_page'] = self.blog_page
(and selecting the correct blog page in the admin) does not work.
Without switching it out, I think I can only ever have a single instance of BlogPage, because all InformationPages will have to pull from the first instance.
Any thoughts?