Tutorial Wagtail Version: 2.x
In Wagtail, and just like in Django, you can subclass classes. In this lesson, we're subclassing a Wagtail Page into 2 child pages. But when we query for all the parent classes, we're also given the child classes in the QuerySet, and the data is somewhat inconsistent because child classes can have unique fields that differ from their parents and siblings.
When you subclass a page in Wagtail and then create a query for all the parent pages, you'll also receive all the child pages with it. Sometimes that's good, sometimes that's bad. In the scenarios where you need additional child page fields you can't simply loop through your QuerySet and get them all. Instead, you'll need to use .specific
in your template, or .specific(defer=False)
in your Python view.
Below is an example of a QuerySet that's looped in our template, and some model assumptions.
In the above template we're checking for .specific
which basically means: Check if there's a child page and if that child page has a property/field called subtitle
.
If you'd like to see the entire git commit, you can check it out here: https://github.com/CodingForEverybody/learn-wagtail/commit/08fbcd67748cec18d9fd8a59fd3c775f6be07aae
Headless CMS: Custom Page Properties
Posted on
If you want to add data custom data (or a function output) to your headless Wagtail API, you can use a @property. In this tutorial I'll show you how easy it can be!
Getting Started With Your First Home Page
Posted on
Learn how to work with Wagtails default Home Page class, and how to extend it with a simple Django model field. WE'll also explore a custom template and how to extend it.
How to Add a New Wagtail Page From Scratch
Posted on
In this video we're going to explore how to add a new app to our Wagtail CMS website, how to install it, and how to add the custom page model. We'll be creating a brand new Wagtail Page from scratch.
How to Subclass Wagtail Pages
Posted on
Subclassing is having a class (in this case it's a Wagtail Page) that can be used for other classes (Wagtail Page's). The parent class has all the common attributes for the child pages, and every child page will inherit everything from it's parent. In this lesson we'll explore that by creating a subclassed Article and Video Blog Page that share a common parent, and then we'll extend the functionality of both subclassed pages by adding new fields.
This course covers everything from basic installation to advanced features like custom blocks and API integration, it's perfect for developers looking to enhance their skills with this powerful CMS.