Move viewset intro in generic views docs to the base `ViewSet` usage docs

pull/11170/head
Sage Abdullah 2023-10-30 16:24:28 +00:00 zatwierdzone przez Matt Westcott
rodzic 43e306a49b
commit 5bf3f7e30d
2 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -232,7 +232,9 @@ The 'Calendar' item will now appear as a group of menu items. When expanded, the
## Using `ViewSet` to group custom admin views
Wagtail provides a {class}`~wagtail.admin.viewsets.base.ViewSet` class that combines the registration of views and the associated menu item into a single class. For example, you can group the calendar views from the previous example into a single menu item by creating a `ViewSet` subclass in `views.py`:
Registering admin views along with their URLs and menu items is a common pattern in Wagtail. This often involves several related views with shared properties such as the model that we're working with, and its associated icon. To support the pattern, Wagtail implements the concept of a _viewset_, which allows a bundle of views and their URLs to be defined collectively, along with a menu item to be registered with the admin app as a single operation through the [`register_admin_viewset`](register_admin_viewset) hook.
For example, you can group the calendar views from the previous example into a single menu item by creating a {class}`~wagtail.admin.viewsets.base.ViewSet` subclass in `views.py`:
```{code-block} python
from wagtail.admin.viewsets.base import ViewSet
@ -261,7 +263,7 @@ class CalendarViewSet(ViewSet):
]
```
Then, remove the `register_admin_urls` and `register_admin_menu_item` hooks in `wagtail_hooks.py` in favor of registering the `ViewSet` subclass with the [`register_admin_viewset`](register_admin_viewset) hook:
Then, remove the `register_admin_urls` and `register_admin_menu_item` hooks in `wagtail_hooks.py` in favor of registering the `ViewSet` subclass with the `register_admin_viewset` hook:
```{code-block} python
from .views import CalendarViewSet

Wyświetl plik

@ -2,7 +2,7 @@
# 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`](register_admin_viewset) hook.
Wagtail provides several generic views for handling common tasks such as creating / editing model instances and chooser modals. For convenience, these views are bundled in [viewsets](viewsets_reference).
## ModelViewSet