Wagtail API, Single endpoint with different ViewSets

I'm using Wagtail API to set up a site with a single endpoint, but different Page types under that endpoint. In short, I have two models

class TeamPage(Page)


class BlogPage(Page):

and I want the following url paths

GET /teams - TeamsAPIViewSet.listing_view to return a list of all TeamPages
GET /teams/<slug> - TeamsAPIViewSet.detail_view to return the detail for a single TeamPage
GET /teams/<slug>/blogs - BlogsAPIViewSet.listing_view to return a list of all BlogPages for a specific team
GET /teams/<slug>/blogs - BlogsAPIViewSet.detail_view to return a specific BlogPage

Registering the "teams" endpoint in api.py only allows a single ViewSet for that endpoint

api_router.register_endpoint('teams', TeamsAPIViewSet)

so, /api/teams will always use the TeamsAPIViewSet.

I tried setting up paths in urls.py as follows:

path('api/teams/', TeamsAPIViewSet.as_view({"get": "listing_view"}), name="listing"),
path('api/teams/<slug:slug>/', TeamsAPIViewSet.as_view({'get': 'detail_view'})),
path('api/teams/<slug:team_slug>/<slug:slug>', ContentAPIViewSet.as_view({'get': 'detail_view'})),
path('api/teams/<slug:team_slug>/blogs/', BlogsAPIViewSet.as_view({'get': 'listing_view'})),
path('api/teams/<slug:team_slug>/blogs/<slug:slug>/', BlogsAPIViewSet.as_view({'get'
: 'detail_view'})),

but that throws an exception,

'Request' object has no attribute 'wagtailapi_router'

Any suggestions are appreciated.

Back to Top