```{module} wagtail.admin.viewsets ``` (viewsets_reference)= # 视图集 Viewset 是 Wagtail 的机制,用来把一组相关的管理后台视图连同共享属性,作为一个整体来定义。 ## ViewSet ```{eval-rst} .. autoclass:: wagtail.admin.viewsets.base.ViewSet .. autoattribute:: UNDEFINED :no-value: .. autoattribute:: name .. autoattribute:: url_prefix .. autoattribute:: url_namespace .. automethod:: on_register .. automethod:: get_urlpatterns .. automethod:: get_url_name .. autoattribute:: icon .. autoattribute:: menu_icon 默认为 :attr:`icon`。 .. autoattribute:: menu_label .. autoattribute:: menu_name .. autoattribute:: menu_order .. autoattribute:: menu_url 默认为 :meth:`get_urlpatterns` 返回的第一个 URL。 .. 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: () 要归组在一起的 :class:`~wagtail.admin.viewsets.base.ViewSet` 类或实例的列表或元组。 .. autoattribute:: menu_icon .. autoattribute:: menu_label .. autoattribute:: menu_name .. autoattribute:: menu_order .. autoattribute:: menu_item_class .. autoattribute:: add_to_admin_menu .. autoattribute:: submenu_hook .. automethod:: get_menu_item ``` ## ModelViewSet ```{eval-rst} .. autoclass:: wagtail.admin.viewsets.model.ModelViewSet .. attribute:: model 必需;该 viewset 要处理的模型类。除非通过 :attr:`~.ViewSet.name`、:attr:`~.ViewSet.url_prefix` 或 :attr:`~.ViewSet.url_namespace` 属性显式指定,否则 ``model_name`` 会被用作 URL 前缀和命名空间。 .. attribute:: form_fields 应包含在创建 / 编辑表单中的模型字段名列表。 .. attribute:: exclude_form_fields 用于替代 :attr:`form_fields`,表示模型的所有字段中除这里列出的之外,都应出现在创建 / 编辑表单中。必须提供 ``form_fields`` 或 ``exclude_form_fields`` 之一(除非覆盖了 :meth:`get_form_class`)。 .. automethod:: get_form_class .. automethod:: get_edit_handler .. automethod:: get_permissions_to_register .. autoattribute:: permission_policy .. autoattribute:: menu_label 默认为模型 :attr:`~django.db.models.Options.verbose_name_plural` 的首字母大写形式。 .. autoattribute:: add_to_reference_index .. autoattribute:: pk_path_converter .. autoattribute:: ordering .. autoattribute:: sort_order_field .. autoattribute:: list_per_page .. autoattribute:: list_display 该列表会被传给索引视图的 ``list_display`` 属性。如果未设置,则使用 索引视图的 ``list_display`` 属性,其默认值定义为包含 ``"__str__"``、:class:`LocaleColumn() ` 和 :class:`UpdatedAtColumn() ` 的列表。 注意,只有当模型可翻译时才会包含 ``LocaleColumn``。 .. autoattribute:: list_export .. autoattribute:: list_filter .. autoattribute:: filterset_class .. autoattribute:: export_headings .. autoattribute:: export_filename .. autoattribute:: search_fields .. autoattribute:: search_backend_name .. autoattribute:: copy_view_enabled .. autoattribute:: inspect_view_enabled .. autoattribute:: inspect_view_fields .. autoattribute:: inspect_view_fields_exclude .. autoattribute:: index_view_class .. autoattribute:: add_view_class .. autoattribute:: edit_view_class .. autoattribute:: delete_view_class .. autoattribute:: usage_view_class .. autoattribute:: history_view_class .. autoattribute:: copy_view_class .. autoattribute:: inspect_view_class .. autoattribute:: template_prefix .. 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 .. autoattribute:: inspect_template_name ``` ## ModelViewSetGroup ```{eval-rst} .. autoclass:: wagtail.admin.viewsets.model.ModelViewSetGroup .. autoattribute:: menu_label 如果未设置,默认为第一个 viewset 中模型的 :attr:`~django.db.models.Options.app_label` 的首字母大写形式。 ``` ## ChooserViewSet ```{eval-rst} .. autoclass:: wagtail.admin.viewsets.chooser.ChooserViewSet .. attribute:: model 必需;该 viewset 要处理的模型类。 .. autoattribute:: icon .. autoattribute:: permission_policy .. autoattribute:: choose_one_text .. autoattribute:: page_title .. autoattribute:: choose_another_text .. autoattribute:: edit_item_text .. autoattribute:: per_page .. autoattribute:: preserve_url_parameters .. autoattribute:: url_filter_parameters .. autoattribute:: choose_view_class .. autoattribute:: choose_results_view_class .. autoattribute:: chosen_view_class .. autoattribute:: chosen_multiple_view_class .. autoattribute:: create_view_class .. autoattribute:: base_widget_class .. autoattribute:: widget_class .. autoattribute:: widget_telepath_adapter_class .. autoattribute:: register_widget .. autoattribute:: base_block_class .. automethod:: get_block_class .. 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 .. method:: get_object_list 返回可供选择的对象的 queryset。默认返回 ``model`` 的所有实例。 ``` ## SnippetViewSet ```{eval-rst} .. autoclass:: wagtail.snippets.views.snippets.SnippetViewSet .. autoattribute:: model .. autoattribute:: chooser_per_page .. autoattribute:: admin_url_namespace .. autoattribute:: base_url_path .. autoattribute:: chooser_admin_url_namespace .. autoattribute:: chooser_base_url_path .. autoattribute:: index_view_class .. autoattribute:: add_view_class .. autoattribute:: edit_view_class .. autoattribute:: delete_view_class .. autoattribute:: usage_view_class .. autoattribute:: history_view_class .. autoattribute:: copy_view_class .. autoattribute:: inspect_view_class .. autoattribute:: revisions_view_class .. autoattribute:: revisions_revert_view_class .. autoattribute:: revisions_compare_view_class .. autoattribute:: revisions_unschedule_view_class .. autoattribute:: unpublish_view_class .. autoattribute:: preview_on_add_view_class .. autoattribute:: preview_on_edit_view_class .. autoattribute:: lock_view_class .. autoattribute:: unlock_view_class .. autoattribute:: chooser_viewset_class .. automethod:: get_queryset .. automethod:: get_edit_handler .. 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 .. automethod:: get_inspect_template .. automethod:: get_admin_url_namespace .. automethod:: get_admin_base_path .. automethod:: get_chooser_admin_url_namespace .. automethod:: get_chooser_admin_base_path ``` ## SnippetChooserViewSet ```{eval-rst} .. autoclass:: wagtail.snippets.views.chooser.SnippetChooserViewSet .. autoattribute:: choose_view_class .. autoattribute:: choose_results_view_class .. autoattribute:: chosen_view_class .. autoattribute:: chosen_multiple_view_class .. autoattribute:: create_view_class .. autoattribute:: base_widget_class .. autoattribute:: widget_class ``` ## SnippetViewSetGroup ```{eval-rst} .. autoclass:: wagtail.snippets.views.snippets.SnippetViewSetGroup ``` ## PageListingViewSet ```{eval-rst} .. autoclass:: wagtail.admin.viewsets.pages.PageListingViewSet .. autoattribute:: model .. autoattribute:: index_view_class .. autoattribute:: choose_parent_view_class .. autoattribute:: list_display .. autoattribute:: columns .. autoattribute:: list_filter .. autoattribute:: filterset_class .. autoattribute:: list_per_page .. autoattribute:: list_export .. autoattribute:: export_headings .. autoattribute:: export_filename ``` ## PageViewSet ```{eval-rst} .. autoclass:: wagtail.admin.viewsets.pages.PageViewSet .. autoattribute:: model .. autoattribute:: parent_models .. autoattribute:: list_display .. autoattribute:: columns .. autoattribute:: list_filter .. autoattribute:: filterset_class .. autoattribute:: list_per_page .. autoattribute:: list_export .. autoattribute:: export_headings .. autoattribute:: export_filename .. autoattribute:: choose_parent_view_class .. autoattribute:: content_type_use_view_class .. autoattribute:: add_subpage_view_class .. autoattribute:: add_view_class .. autoattribute:: collect_workflow_action_data_view_class .. autoattribute:: confirm_workflow_cancellation_view_class .. autoattribute:: convert_alias_view_class .. autoattribute:: copy_view_class .. autoattribute:: edit_view_class .. autoattribute:: delete_view_class .. autoattribute:: history_view_class .. autoattribute:: index_view_class .. autoattribute:: lock_view_class .. autoattribute:: move_view_class .. autoattribute:: move_confirm_view_class .. autoattribute:: unlock_view_class .. autoattribute:: preview_on_add_view_class .. autoattribute:: preview_on_edit_view_class .. autoattribute:: revisions_view_class .. autoattribute:: revisions_compare_view_class .. autoattribute:: revisions_revert_view_class .. autoattribute:: revisions_unschedule_view_class .. autoattribute:: search_view_class .. autoattribute:: set_page_position_view_class .. autoattribute:: set_privacy_view_class .. autoattribute:: unpublish_view_class .. autoattribute:: usage_view_class .. autoattribute:: view_draft_view_class .. autoattribute:: workflow_action_view_class .. autoattribute:: workflow_history_view_class .. autoattribute:: workflow_history_detail_view_class .. autoattribute:: workflow_preview_view_class ```