2023-10-31 11:42:17 +00:00
```{module} wagtail.admin.viewsets
2023-11-12 07:04:11 +00:00
2023-10-31 11:42:17 +00:00
```
2023-07-06 10:53:01 +00:00
(viewsets_reference)=
2022-06-09 13:48:47 +00:00
# Viewsets
2023-10-30 15:24:52 +00:00
Viewsets are Wagtail's mechanism for defining a group of related admin views with shared properties, as a single unit.
2022-06-09 13:48:47 +00:00
2022-06-10 19:29:32 +00:00
## ViewSet
2022-06-09 13:48:47 +00:00
2022-06-10 19:29:32 +00:00
```{eval-rst}
2022-06-09 13:48:47 +00:00
.. autoclass:: wagtail.admin.viewsets.base.ViewSet
2023-08-11 19:11:49 +00:00
.. autoattribute:: name
.. autoattribute:: url_prefix
.. autoattribute:: url_namespace
2022-06-09 13:48:47 +00:00
.. automethod:: on_register
.. automethod:: get_urlpatterns
.. automethod:: get_url_name
2023-08-14 12:24:12 +00:00
.. autoattribute:: icon
.. autoattribute:: menu_icon
Defaults to :attr:`icon`.
.. autoattribute:: menu_label
.. autoattribute:: menu_name
.. autoattribute:: menu_order
.. autoattribute:: menu_url
Defaults to the first URL returned by :meth:`get_urlpatterns`.
.. autoattribute:: menu_item_class
.. autoattribute:: menu_hook
.. autoattribute:: add_to_admin_menu
.. autoattribute:: add_to_settings_menu
.. automethod:: get_menu_item
```
## ViewSetGroup
```{eval-rst}
.. autoclass:: wagtail.admin.viewsets.base.ViewSetGroup
.. attribute:: items
:value: ()
A list or tuple of :class:`~wagtail.admin.viewsets.base.ViewSet` classes or instances to be grouped together.
.. autoattribute:: menu_icon
.. autoattribute:: menu_label
.. autoattribute:: menu_name
.. autoattribute:: menu_order
.. autoattribute:: menu_item_class
.. autoattribute:: add_to_admin_menu
.. automethod:: get_menu_item
2022-06-10 19:29:32 +00:00
```
2022-06-09 14:26:30 +00:00
2022-06-10 19:29:32 +00:00
## ModelViewSet
2022-06-09 14:26:30 +00:00
2022-06-10 19:29:32 +00:00
```{eval-rst}
2022-06-09 14:26:30 +00:00
.. autoclass:: wagtail.admin.viewsets.model.ModelViewSet
.. attribute:: model
2024-07-18 23:21:39 +00:00
Required; the model class that this viewset will work with. The ``model_name`` will be used
2023-10-31 11:42:17 +00:00
as the URL prefix and namespace, unless these are specified explicitly via the :attr:`~.ViewSet.name`, :attr:`~.ViewSet.url_prefix` or
:attr:`~.ViewSet.url_namespace` attributes.
2022-06-09 14:26:30 +00:00
.. attribute:: form_fields
A list of model field names that should be included in the create / edit forms.
.. attribute:: exclude_form_fields
2023-10-31 11:42:17 +00:00
Used in place of :attr:`form_fields` to indicate that all of the model's fields except the ones listed here should appear in the create / edit forms. Either ``form_fields`` or ``exclude_form_fields`` must be supplied (unless :meth:`get_form_class` is being overridden).
2022-06-09 14:26:30 +00:00
.. automethod:: get_form_class
2023-08-24 14:06:48 +00:00
.. automethod:: get_edit_handler
2024-05-31 11:09:47 +00:00
.. automethod:: get_permissions_to_register
2022-06-09 14:26:30 +00:00
2023-08-14 12:24:12 +00:00
.. autoattribute:: menu_label
Defaults to the title-cased version of the model's
:attr:`~django.db.models.Options.verbose_name_plural`.
2023-08-16 10:22:49 +00:00
.. autoattribute:: add_to_reference_index
2023-10-31 11:40:34 +00:00
.. autoattribute:: ordering
2023-08-23 15:13:03 +00:00
.. autoattribute:: list_per_page
2023-08-17 12:49:52 +00:00
.. autoattribute:: list_display
2023-08-23 10:37:37 +00:00
.. autoattribute:: list_export
2023-08-21 12:18:27 +00:00
.. autoattribute:: list_filter
.. autoattribute:: filterset_class
2023-08-23 15:45:56 +00:00
.. autoattribute:: export_headings
2023-08-23 10:37:37 +00:00
.. autoattribute:: export_filename
2023-08-22 14:10:32 +00:00
.. autoattribute:: search_fields
.. autoattribute:: search_backend_name
2023-11-21 18:50:54 +00:00
.. autoattribute:: copy_view_enabled
2023-10-05 13:06:18 +00:00
.. autoattribute:: inspect_view_enabled
.. autoattribute:: inspect_view_fields
.. autoattribute:: inspect_view_fields_exclude
2022-06-09 14:26:30 +00:00
.. autoattribute:: index_view_class
.. autoattribute:: add_view_class
.. autoattribute:: edit_view_class
.. autoattribute:: delete_view_class
2023-09-19 16:18:13 +00:00
.. autoattribute:: usage_view_class
2023-10-05 13:06:18 +00:00
.. autoattribute:: history_view_class
2023-11-21 18:50:54 +00:00
.. autoattribute:: copy_view_class
2023-10-05 13:06:18 +00:00
.. autoattribute:: inspect_view_class
2023-08-15 14:39:57 +00:00
.. autoattribute:: template_prefix
.. autoattribute:: index_template_name
.. autoattribute:: index_results_template_name
.. autoattribute:: create_template_name
.. autoattribute:: edit_template_name
.. autoattribute:: delete_template_name
2023-09-18 14:52:14 +00:00
.. autoattribute:: history_template_name
2023-10-05 13:06:18 +00:00
.. autoattribute:: inspect_template_name
2022-06-10 19:29:32 +00:00
```
2022-06-09 14:59:52 +00:00
2023-08-14 12:24:12 +00:00
## ModelViewSetGroup
```{eval-rst}
.. autoclass:: wagtail.admin.viewsets.model.ModelViewSetGroup
.. autoattribute:: menu_label
If unset, defaults to the title-cased version of the model's
:attr:`~django.db.models.Options.app_label` from the first viewset.
```
2022-06-10 19:29:32 +00:00
## ChooserViewSet
2022-06-09 14:59:52 +00:00
2022-06-10 19:29:32 +00:00
```{eval-rst}
2022-06-09 14:59:52 +00:00
.. autoclass:: wagtail.admin.viewsets.chooser.ChooserViewSet
.. attribute:: model
Required; the model class that this viewset will work with.
.. autoattribute:: icon
.. autoattribute:: choose_one_text
.. autoattribute:: page_title
.. autoattribute:: choose_another_text
.. autoattribute:: edit_item_text
2022-07-14 11:33:28 +00:00
.. autoattribute:: per_page
2023-01-12 21:17:37 +00:00
.. autoattribute:: preserve_url_parameters
2023-09-04 23:46:16 +00:00
.. autoattribute:: url_filter_parameters
2022-06-09 14:59:52 +00:00
.. autoattribute:: choose_view_class
.. autoattribute:: choose_results_view_class
.. autoattribute:: chosen_view_class
2023-01-12 15:52:42 +00:00
.. autoattribute:: chosen_multiple_view_class
2022-06-22 11:29:27 +00:00
.. autoattribute:: create_view_class
2022-07-07 22:37:03 +00:00
.. autoattribute:: base_widget_class
2022-06-09 14:59:52 +00:00
.. autoattribute:: widget_class
2022-08-17 12:26:59 +00:00
.. autoattribute:: widget_telepath_adapter_class
2022-06-09 14:59:52 +00:00
.. autoattribute:: register_widget
2022-07-07 22:37:03 +00:00
.. autoattribute:: base_block_class
2022-08-16 13:58:40 +00:00
.. automethod:: get_block_class
2022-06-21 17:11:27 +00:00
.. autoattribute:: creation_form_class
.. autoattribute:: form_fields
.. autoattribute:: exclude_form_fields
.. autoattribute:: create_action_label
.. autoattribute:: create_action_clicked_label
.. autoattribute:: creation_tab_label
.. autoattribute:: search_tab_label
2023-09-04 17:45:39 +00:00
.. method:: get_object_list
Returns a queryset of objects that are available to be chosen. By default, all instances of ``model`` are returned.
2022-06-09 13:48:47 +00:00
```
2022-09-14 14:33:32 +00:00
## SnippetViewSet
```{eval-rst}
.. autoclass:: wagtail.snippets.views.snippets.SnippetViewSet
2023-04-13 11:11:41 +00:00
.. autoattribute:: model
2023-04-29 04:58:23 +00:00
.. autoattribute:: chooser_per_page
2023-03-15 15:07:19 +00:00
.. autoattribute:: admin_url_namespace
.. autoattribute:: base_url_path
2023-03-16 16:44:32 +00:00
.. autoattribute:: chooser_admin_url_namespace
.. autoattribute:: chooser_base_url_path
2022-09-14 14:33:32 +00:00
.. autoattribute:: index_view_class
.. autoattribute:: add_view_class
.. autoattribute:: edit_view_class
.. autoattribute:: delete_view_class
.. autoattribute:: usage_view_class
.. autoattribute:: history_view_class
2023-11-21 18:50:54 +00:00
.. autoattribute:: copy_view_class
2023-06-30 16:42:57 +00:00
.. autoattribute:: inspect_view_class
2022-09-14 14:33:32 +00:00
.. autoattribute:: revisions_view_class
.. autoattribute:: revisions_revert_view_class
.. autoattribute:: revisions_compare_view_class
2022-12-06 17:36:17 +00:00
.. autoattribute:: revisions_unschedule_view_class
2022-09-14 14:33:32 +00:00
.. autoattribute:: unpublish_view_class
.. autoattribute:: preview_on_add_view_class
.. autoattribute:: preview_on_edit_view_class
2022-12-06 17:36:17 +00:00
.. autoattribute:: lock_view_class
.. autoattribute:: unlock_view_class
2023-03-27 10:06:57 +00:00
.. autoattribute:: chooser_viewset_class
2023-03-28 12:43:16 +00:00
.. automethod:: get_queryset
2023-03-31 14:10:10 +00:00
.. automethod:: get_edit_handler
2023-03-27 13:52:04 +00:00
.. automethod:: get_index_template
.. automethod:: get_index_results_template
.. automethod:: get_create_template
.. automethod:: get_edit_template
.. automethod:: get_delete_template
.. automethod:: get_history_template
2023-06-30 16:42:57 +00:00
.. automethod:: get_inspect_template
2023-03-15 15:07:19 +00:00
.. automethod:: get_admin_url_namespace
.. automethod:: get_admin_base_path
2023-03-16 16:44:32 +00:00
.. automethod:: get_chooser_admin_url_namespace
.. automethod:: get_chooser_admin_base_path
2022-09-14 14:33:32 +00:00
```
2023-04-13 14:10:09 +00:00
## SnippetViewSetGroup
```{eval-rst}
.. autoclass:: wagtail.snippets.views.snippets.SnippetViewSetGroup
```
2024-03-05 19:05:20 +00:00
## PageListingViewSet
```{eval-rst}
.. autoclass:: wagtail.admin.viewsets.pages.PageListingViewSet
.. autoattribute:: model
.. autoattribute:: index_view_class
2024-03-09 22:27:47 +00:00
.. autoattribute:: choose_parent_view_class
2024-03-05 19:05:20 +00:00
.. autoattribute:: columns
.. autoattribute:: filterset_class
```