Sfoglia il codice sorgente

Document `register_admin_viewset` hook

Sage Abdullah 1 anno fa
parent
commit
622b71654c
2 ha cambiato i file con 25 aggiunte e 1 eliminazioni
  1. 1 1
      docs/extending/generic_views.md
  2. 24 0
      docs/reference/hooks.md

+ 1 - 1
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
 

+ 24 - 0
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`