Tutorial Wagtail Version: 2.x
When querying for a Wagtail Page that has child (Subclassed) pages, you'll receive all of the pages in your QuerySet. There are times when you simply want the child pages (all types), a specific type of child page, or just the parent page itself with no children. In this lesson we'll explore Wagtails .not_exact_type() and .exact_type() methods.
There are several ways to query your Wagtail Pages and return QuerySets containing only the page classes you want. Below is some example code.
This example assumes that there are child (subclassed) pages that inherit form
This example assumes each child page is inheriting from
BlogDetailPage. This will return a QuerySet of
BlogDetailPage's, not the actual class you'd be expecting.
If you're trying to query for all child pages that inherit from a parent page (ie.
BlogDetailPage), you'll receive a QuerySet of
BlogDetailPage's. To get the specific child pages, append
.specific() to your query.
Wagtail is built for speed and efficiency. It's easy to get away from that and write code that performs terribly. So by default the
.specific() argument called defer is set to
.specific(defer=True)). Grabbing specific fields from a model means adding another database hit, and if the QuerySet is large, this can become a problem. So it's good that specific property deferring is enabled by default.
But occasionally you want the specific properties of a class. To disabled property deferring simply append
.specific(defer=False) to your ORM Query.
Wagtail comes with a lot of different QuerySet options. This lesson only went over 2 of them, but there are many more. Definitely take a couple minutes and read through their docs page.
This lesson works purely in the Django Shell and doesn't have any code to committed to the repo. Above is where you can find example code.
Getting Started With Your First Home Page
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
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 Add a Blog Listing Page, Blog Detail Page, and Custom Context
In this (long) lesson we're going to cover three main topics. They all go hand-in-hand with Wagtail CMS so it makes sense to learn them all together. The three topics are: Listing Pages, Detail Pages and Adding Custom Context to your pages.