2023-07-06 12:53:01 +02:00
(viewsets_reference)=
2022-06-09 15:48:47 +02:00
# Viewsets
Viewsets are Wagtail's mechanism for defining a group of related admin views with shared properties, as a single unit. See [Generic views ](../extending/generic_views ).
2022-06-10 21:29:32 +02:00
## ViewSet
2022-06-09 15:48:47 +02:00
2022-06-10 21:29:32 +02:00
```{eval-rst}
2022-06-09 15:48:47 +02:00
.. autoclass:: wagtail.admin.viewsets.base.ViewSet
.. automethod:: on_register
.. automethod:: get_urlpatterns
.. automethod:: get_url_name
2022-06-10 21:29:32 +02:00
```
2022-06-09 16:26:30 +02:00
2022-06-10 21:29:32 +02:00
## ModelViewSet
2022-06-09 16:26:30 +02:00
2022-06-10 21:29:32 +02:00
```{eval-rst}
2022-06-09 16:26:30 +02:00
.. autoclass:: wagtail.admin.viewsets.model.ModelViewSet
.. attribute:: model
Required; the model class that this viewset will work with.
.. attribute:: form_fields
A list of model field names that should be included in the create / edit forms.
.. attribute:: exclude_form_fields
Used in place of ``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 ``get_form_class`` is being overridden).
.. automethod:: get_form_class
.. autoattribute:: icon
.. autoattribute:: index_view_class
.. autoattribute:: add_view_class
.. autoattribute:: edit_view_class
.. autoattribute:: delete_view_class
2022-06-10 21:29:32 +02:00
```
2022-06-09 16:59:52 +02:00
2022-06-10 21:29:32 +02:00
## ChooserViewSet
2022-06-09 16:59:52 +02:00
2022-06-10 21:29:32 +02:00
```{eval-rst}
2022-06-09 16:59:52 +02: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 13:33:28 +02:00
.. autoattribute:: per_page
2023-01-12 22:17:37 +01:00
.. autoattribute:: preserve_url_parameters
2022-06-09 16:59:52 +02:00
.. autoattribute:: choose_view_class
.. autoattribute:: choose_results_view_class
.. autoattribute:: chosen_view_class
2023-01-12 16:52:42 +01:00
.. autoattribute:: chosen_multiple_view_class
2022-06-22 13:29:27 +02:00
.. autoattribute:: create_view_class
2022-07-08 00:37:03 +02:00
.. autoattribute:: base_widget_class
2022-06-09 16:59:52 +02:00
.. autoattribute:: widget_class
2022-08-17 14:26:59 +02:00
.. autoattribute:: widget_telepath_adapter_class
2022-06-09 16:59:52 +02:00
.. autoattribute:: register_widget
2022-07-08 00:37:03 +02:00
.. autoattribute:: base_block_class
2022-08-16 15:58:40 +02:00
.. automethod:: get_block_class
2022-06-21 19:11:27 +02: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
2022-06-09 15:48:47 +02:00
```
2022-09-14 16:33:32 +02:00
## SnippetViewSet
```{eval-rst}
.. autoclass:: wagtail.snippets.views.snippets.SnippetViewSet
2023-04-13 13:11:41 +02:00
.. autoattribute:: model
2022-12-17 12:21:58 +01:00
.. autoattribute:: icon
2023-04-12 18:26:00 +02:00
.. autoattribute:: add_to_admin_menu
.. autoattribute:: add_to_settings_menu
.. autoattribute:: menu_label
.. autoattribute:: menu_name
.. autoattribute:: menu_order
2022-09-27 13:58:11 +02:00
.. autoattribute:: list_display
2023-07-03 16:18:02 +02:00
.. autoattribute:: list_export
2023-03-20 18:00:26 +01:00
.. autoattribute:: list_filter
.. autoattribute:: filterset_class
2023-03-29 16:40:57 +02:00
.. autoattribute:: search_fields
.. autoattribute:: search_backend_name
2023-03-17 16:27:48 +01:00
.. autoattribute:: list_per_page
2023-04-29 06:58:23 +02:00
.. autoattribute:: chooser_per_page
2023-07-10 11:20:04 +02:00
.. autoattribute:: export_filename
2023-04-03 13:50:20 +02:00
.. autoattribute:: ordering
2023-06-30 18:42:57 +02:00
.. autoattribute:: inspect_view_enabled
.. autoattribute:: inspect_view_fields
.. autoattribute:: inspect_view_fields_exclude
2023-03-15 16:07:19 +01:00
.. autoattribute:: admin_url_namespace
.. autoattribute:: base_url_path
2023-03-16 17:44:32 +01:00
.. autoattribute:: chooser_admin_url_namespace
.. autoattribute:: chooser_base_url_path
2022-09-14 16:33:32 +02: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-06-30 18:42:57 +02:00
.. autoattribute:: inspect_view_class
2022-09-14 16:33:32 +02:00
.. autoattribute:: revisions_view_class
.. autoattribute:: revisions_revert_view_class
.. autoattribute:: revisions_compare_view_class
2022-12-06 18:36:17 +01:00
.. autoattribute:: revisions_unschedule_view_class
2022-09-14 16:33:32 +02:00
.. autoattribute:: unpublish_view_class
.. autoattribute:: preview_on_add_view_class
.. autoattribute:: preview_on_edit_view_class
2022-12-06 18:36:17 +01:00
.. autoattribute:: lock_view_class
.. autoattribute:: unlock_view_class
2023-03-27 12:06:57 +02:00
.. autoattribute:: chooser_viewset_class
2023-04-04 12:43:29 +02:00
.. autoattribute:: template_prefix
2023-03-27 15:52:04 +02:00
.. autoattribute:: index_template_name
.. autoattribute:: index_results_template_name
.. autoattribute:: create_template_name
.. autoattribute:: edit_template_name
.. autoattribute:: delete_template_name
.. autoattribute:: history_template_name
2023-04-12 18:26:00 +02:00
.. automethod:: get_menu_label
.. automethod:: get_menu_name
.. automethod:: get_menu_icon
.. automethod:: get_menu_order
.. automethod:: get_menu_item
2023-03-28 14:43:16 +02:00
.. automethod:: get_queryset
2023-03-31 16:10:10 +02:00
.. automethod:: get_edit_handler
.. automethod:: get_form_class
2023-03-27 15:52:04 +02: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 18:42:57 +02:00
.. automethod:: get_inspect_template
2023-03-15 16:07:19 +01:00
.. automethod:: get_admin_url_namespace
.. automethod:: get_admin_base_path
2023-03-16 17:44:32 +01:00
.. automethod:: get_chooser_admin_url_namespace
.. automethod:: get_chooser_admin_base_path
2022-09-14 16:33:32 +02:00
```
2023-04-13 16:10:09 +02:00
## SnippetViewSetGroup
```{eval-rst}
.. autoclass:: wagtail.snippets.views.snippets.SnippetViewSetGroup
.. autoattribute:: items
.. autoattribute:: add_to_admin_menu
.. autoattribute:: menu_label
.. autoattribute:: menu_name
.. autoattribute:: menu_icon
.. autoattribute:: menu_order
.. automethod:: get_menu_label
.. automethod:: get_menu_name
.. automethod:: get_menu_icon
.. automethod:: get_menu_order
.. automethod:: get_menu_item
```