Add proper category system for main navigation and content organisation #35
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
All articles currently live under a single
/articles/page with flat tag-based filtering (?tag=slug). There is no concept of categories — everything is lumped together under "Articles". For a professional blog/articles site, categories should provide primary content organisation that's visible in the site's main navigation, with tags remaining as secondary cross-cutting labels.Current State
HomePage → ArticleIndexPage → ArticlePage(flat, single index)TagMetadatafor colours)SiteSettings.navigation_items(orderable, manually configured)/articles/(all),/articles/?tag=slug(filtered),/articles/slug/(detail)/feed/(all articles),/feed/tag/<slug>/(per-tag)What's Wrong
Proposed Solution: Category Snippet + RoutablePageMixin
Add a
CategoryWagtail snippet model and enhanceArticleIndexPagewithRoutablePageMixinfor clean category URLs.Why a Snippet, Not a Page Type?
ArticleIndexPage(no URL changes to existing content)Category vs Tag (After)
/articles/category/<slug>//articles/?tag=<slug>URL Structure (After)
/articles//articles/category/<slug>//articles/?tag=<slug>/articles/<article-slug>//feed//feed/category/<slug>//feed/tag/<slug>/Navigation Integration
Categories auto-populate in the main nav via a new template tag. Two presentation options:
Implementation supports both — a
get_categories_navtemplate tag provides the data and the template decides presentation.Implementation Plan
1. Create Category Model
New
Categorysnippet model inapps/blog/models.py:Register as Wagtail snippet via
SnippetViewSetinapps/blog/wagtail_hooks.py.2. Add Category FK to ArticlePage
category = models.ForeignKey("blog.Category", on_delete=PROTECT)FieldPanel("category")tocontent_panels3. Enhance ArticleIndexPage with RoutablePageMixin
RoutablePageMixintoArticleIndexPage@route(r'^category/(?P<category_slug>[-\w]+)/$')for category filtering/articles/category/reviews/?tag=pythonactive_categoryto template context4. Create Category Navigation Template Tag
get_categories_navtag inapps/core/templatetags/core_tags.pyshow_in_nav=True, ordered bysort_order5. Update Nav Template
templates/components/nav.html6. Update Article Index Template
article_index_page.html(above or alongside tag filters)7. Update Homepage Template
home_page.html8. Add Per-Category RSS Feed
CategoryArticlesFeedclass inapps/blog/feeds.py/feed/category/<slug>/inconfig/urls.py9. Update and Add Tests
Categorymodel and snippet registrationArticleIndexPagecategory routing (200s, 404 for bad slugs)10. Seed Data Migration
Considerations
?tag=continues to work identically.category.description, and sitemap entries via RoutablePageMixin.COLOUR_CHOICES(cyan, pink, neutral) fromTagMetadata.mark referenced this issue2026-03-03 11:21:29 +00:00