I am working with Wagtail CMS (version 6.1) and have implemented a topic chooser view set to allow selecting and creating topics that are applied to content such as news items. These topics inherit from the Wagtail page model, enabling the creation of topic listing pages.
The issue arises when creating a new topic via the chooser view set modal. Since topics are Wagtail pages, they require a parent page to be specified within the TreeBeard hierarchical model. However, Wagtail ChooserViewSet form displays the required TreeBeard metadata such as path
and depth
, which the user won’t necessarily know.
How can I automatically specify the single instance of the topic index page when creating a new topic via the chooser view set?
class TopicIndexPage(Page):
subpage_types: list[str] = ["Topic"]
# Only one instance
max_count = 1
class Topic(Page):
parent_page_types = ["TopicIndexPage"]
subpage_types: list[str] = []
class TopicChooserViewSet(ChooserViewSet):
icon = "tag"
model = Topic
choose_one_text = "Choose a topic"
choose_another_text = "Choose another topic"
# TODO: determine how to enable editing/creation of topics
# which is made difficult since they are pages,
# so need to be placed into the Wagtail page tree
edit_item_text = "Edit topic"
# Show all internal fields,
# otherwise will get 500 server error that `path` and `depth` are required
exclude_form_fields = []