I am working with Wagtail CMS (version 6.1) and have implemented a PageListingViewSet to list news items, which inherit from the Wagtail page model. Everything functions correctly, but when I click the button to create a new news item, Wagtail prompts me to choose the parent page.
Given that I only have one “news index page,” I want to avoid having to select this parent page manually each time a new news item is created. How can I automatically select the single NewsIndexPage instance when creating a news item?
class NewsIndexPage(Page):
...
# Only one news index page
max_count = 1
#
subpage_types: list[str] = [
"NewsItem",
]
class NewsItem(Page):
...
# Only allow news under news index page
parent_page_types = [
"NewsIndexPage",
]
class NewsItemViewSet(PageListingViewSet):
model = NewsItem
menu_label = "News Items"
icon = "list-ul"
add_to_admin_menu = True
1