Ashish Pitrodafield notes
All episodes

Wagtail Unboxed episode 08 4:37

Snippets and reusable content

Content that isn't a page: a team member, a testimonial. No URL, no place in the tree, but they belong on several pages. That is a snippet. Plus tags for the journal.

What this episode covers

And the bug that tag filtering introduces: click "Older" on a filtered list and page 2 quietly shows every post, because the pagination link forgot the tag.

What you'll learn

  • What a snippet is, and when content should be one instead of a page
  • TeamMember with Orderable — drag-and-drop ordering for free
  • SnippetViewSet and SnippetViewSetGroup: the Wagtail 7 way to register snippets
  • Two ways to use a snippet: chosen per page, or fetched by the block
  • get_context on a block
  • The circular import between blocks.py and models.py, and the two ways around it
  • What happens when you delete a snippet a page is using
  • Tags with ClusterTaggableManager, and why the through model needs a ParentalKey
  • Filtering by tag, and keeping the filter through pagination

Chapters

  1. 0:00 Content that isn't a page
  2. 0:23 Two snippet models
  3. 0:39 SnippetViewSet
  4. 1:01 Two ways to use a snippet
  5. 1:24 get_context on a block
  6. 1:36 The circular import
  7. 1:57 Deleting a snippet a page uses
  8. 2:29 Tags, and why ParentalKey
  9. 2:49 Filtering by tag
  10. 3:00 Pagination forgets the filter
  11. 3:17 Carry every parameter
  12. 3:36 Fixed on the way
  13. 3:51 The team
  14. 3:59 A testimonial
  15. 4:06 The journal, filtered
  16. 4:13 Commit and tag
  17. 4:17 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.

Next: episode 09, Navigation and site settings

Carry on from here.

Episode 09 or see all episodes