소스 검색

Document `register_admin_viewset` hook

Sage Abdullah 1 년 전
부모
커밋
622b71654c
2개의 변경된 파일25개의 추가작업 그리고 1개의 파일을 삭제
  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`