Detecting parent and child page types with Python using Wagtail CMS

Viewed 1453

I am setting up a Wagtail website.

There will be an Event Index page with Events as child pages.

Each event page could also have child pages, if it is part of a event series.

The main event will show the child events as a series of links on the page. The child events also need to display the parent event and also its own siblings.

In models.py I have an Event class. So far I am detecting children, siblings, parents like this:

@property
def childpages(self):
    event_children = Event.objects.live().descendant_of(self)
    return event_children

@property
def parentpage(self):
    event_parent = self.get_parent()
    return event_parent

@property
def siblingpages(self):
    event_siblings = Event.objects.live().sibling_of(self, inclusive=False)
    return event_siblings

Is there a way of finding out what the parent page type is? If it is the event index I wouldn't want to display it on the event page. I also wouldn't want the main event pages to show siblings.

I've tried various things with not_child_of(somepage) but not quite sure how to use this. What does 'somepage' reference? A class, a variable? I'm used to Javascript and pretty new to Python.

1 Answers
Related