From 1d295276de3c2dd90225c70af9df4adf73063b5a Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Mon, 30 Oct 2023 15:19:00 +0000 Subject: [PATCH] Document `register_admin_viewset` hook --- docs/extending/generic_views.md | 2 +- docs/reference/hooks.md | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/extending/generic_views.md b/docs/extending/generic_views.md index 824801d78e..59a7ca7abc 100644 --- a/docs/extending/generic_views.md +++ b/docs/extending/generic_views.md @@ -1,6 +1,6 @@ # Generic views -Wagtail provides several generic views for handling common tasks such as creating / editing model instances and chooser modals. Since these often involve several related views with shared properties (such as the model that we're working with, and its associated icon) Wagtail also implements the concept of a _viewset_, which allows a bundle of views to be defined collectively, and their URLs to be registered with the admin app as a single operation through the `register_admin_viewset` hook. +Wagtail provides several generic views for handling common tasks such as creating / editing model instances and chooser modals. Since these often involve several related views with shared properties (such as the model that we're working with, and its associated icon) Wagtail also implements the concept of a _viewset_, which allows a bundle of views to be defined collectively, and their URLs to be registered with the admin app as a single operation through the [`register_admin_viewset`](register_admin_viewset) hook. ## ModelViewSet diff --git a/docs/reference/hooks.md b/docs/reference/hooks.md index d0d417ac17..669d616ff6 100644 --- a/docs/reference/hooks.md +++ b/docs/reference/hooks.md @@ -290,6 +290,30 @@ def urlconf_time(): ] ``` +(register_admin_viewset)= + +### `register_admin_viewset` + +Register a {class}`~wagtail.admin.viewsets.base.ViewSet` or {class}`~wagtail.admin.viewsets.base.ViewSetGroup` to the admin, which combines a set of views, URL patterns, and menu item into a single unit. The callable fed into this hook should return an instance of `ViewSet` or `ViewSetGroup`. + +```python +from .views import CalendarViewSet + +@hooks.register("register_admin_viewset") +def register_viewset(): + return CalendarViewSet() +``` + +Alternatively, it can also return a list of `ViewSet` or `ViewSetGroup` instances. + +```python +from .views import AgendaViewSetGroup, VenueViewSet + +@hooks.register("register_admin_viewset") +def register_viewsets(): + return [AgendaViewSetGroup(), VenueViewSet()] +``` + (register_group_permission_panel)= ### `register_group_permission_panel`