Wagtail Unboxed episode 07 5:25
A blog: parent and child pages
The studio site gets a journal: an index page, posts under it, newest first, three at a time. Our first app of our own.
What this episode covers
Two things go wrong for nearly everyone. With no rules, Wagtail lets an editor put a second homepage inside your About page. And the obvious query for “newest posts first” throws a FieldError.
The build: adding a second app, and why a page app needs no admin.py or views.py; BlogIndexPage and BlogPage, and why the date is its own field; and the page-type rules — parent_page_types, subpage_types, max_count and max_count_per_parent.
The query: why get_children() returns Page, not BlogPage, and the FieldError that causes; BlogPage.objects.child_of(self) for querying the model you actually mean; get_context for handing extra data to a page's template; and pagination, with why get_page() beats page().
Every rule and query in the video was checked against the running site.
Chapters
- 0:00 A studio that never says anything
- 0:20 A second app
- 0:38 Why a separate app
- 0:59 Two models
- 1:23 With no rules, anything goes anywhere
- 1:45 Two lists fix it
- 2:03 Checked, and no migration needed
- 2:25 The query everybody writes first
- 2:39 FieldError, and Page objects
- 2:52 Why get_children() lies to you
- 3:16 get_context
- 3:36 page() vs get_page()
- 3:54 The index template
- 4:09 The counter that jumped sideways
- 4:26 The journal
- 4:34 Page 3, and page 999
- 4:49 A post
- 5:00 Commit and tag
- 5:03 Next episode
Versions on screen
Wagtail 7.4.3 · Django 6.1.1 · Python 3.12. Recorded on Windows; macOS and Linux commands are in the repository for every episode.