<a id="module-wagtail.admin.viewsets"></a>

<a id="viewsets-reference"></a>

# 视图集

Viewset 是 Wagtail 的机制，用来把一组相关的管理后台视图连同共享属性，作为一个整体来定义。

## ViewSet

### *class* wagtail.admin.viewsets.base.ViewSet(name=None, \*\*kwargs)

Defines a viewset to be registered with the Wagtail admin.

All properties of the viewset can be defined as class-level attributes, or passed as
keyword arguments to the constructor (in which case they will override any class-level
attributes). Additionally, the [`name`](#wagtail.admin.viewsets.base.ViewSet.name) property can be passed as the first positional
argument to the constructor.

For more information on how to use this class, see [使用 ViewSet 把自定义管理后台视图分组](../extending/admin_views.html.md#using-base-viewset).

#### UNDEFINED

A special value that, when passed in a kwargs dict to construct a view, indicates that
the attribute should not be written and should instead be left as the view's initial value.

#### name *= None*

A name for this viewset, used as the default URL prefix and namespace.

#### url_prefix

The preferred URL prefix for views within this viewset. When registered through
Wagtail's [register_admin_viewset](hooks.html.md#register-admin-viewset) hook, this will be used as the URL path component
following `/admin/`. Other URL registration mechanisms (e.g. editing `urls.py` manually)
may disregard this and use a prefix of their own choosing.

Defaults to the viewset's `name`.

#### url_namespace

The URL namespace for views within this viewset. Will be used internally as the
application namespace for the viewset's URLs, and generally be the instance namespace
too.

Defaults to the viewset's `name`.

#### on_register()

Called when the viewset is registered; subclasses can override this to perform additional setup.

#### get_urlpatterns()

Returns a set of URL routes to be registered with the Wagtail admin.

#### get_url_name(view_name)

Returns the namespaced URL name for the given view.

#### icon *= ''*

The icon to use across the views.

#### menu_icon

The icon used for the menu item that appears in Wagtail's sidebar.

默认为 [`icon`](#wagtail.admin.viewsets.base.ViewSet.icon)。

#### menu_label *= ''*

The displayed label used for the menu item.

#### menu_name *= ''*

The `name` argument passed to the `MenuItem` constructor, becoming the `name` attribute value for that instance.
This can be useful when manipulating the menu items in a custom menu hook, e.g. [construct_main_menu](hooks.html.md#construct-main-menu).
If unset, a slugified version of [`menu_label`](#wagtail.admin.viewsets.base.ViewSet.menu_label) is used.

#### menu_order *= None*

An integer determining the order of the menu item, 0 being the first place.
If left unset, the order defaults to this item's position within its
containing group (such as a [`ViewSetGroup`](#wagtail.admin.viewsets.base.ViewSetGroup)),
if any. Otherwise, it is set to 8999, placing it as the last item before
Reports, whose order is 9000.

#### Versionchanged
在 8.0 版本发生变更: The value is now respected when the menu item is registered as part of a group.

#### menu_url

The URL to be used for the menu item.

默认为 [`get_urlpatterns()`](#wagtail.admin.viewsets.base.ViewSet.get_urlpatterns) 返回的第一个 URL。

#### menu_item_class

A `wagtail.admin.menu.MenuItem` subclass to be registered with a menu hook.

#### menu_hook

The name of the hook to register the menu item within.

This takes precedence over `add_to_admin_menu` and `add_to_settings_menu`.

#### add_to_admin_menu *= False*

Register the menu item within the admin's main menu.

#### add_to_settings_menu *= False*

Register the menu item within the admin's "Settings" menu.
This takes precedence if both `add_to_admin_menu` and `add_to_settings_menu` are set to `True`.

#### get_menu_item(order=None)

Returns a `wagtail.admin.menu.MenuItem` instance to be registered
with the Wagtail admin.

The `order` parameter allows specifying the order of the menu item when
creating the menu item if the [`menu_order`](#wagtail.admin.viewsets.base.ViewSet.menu_order) attribute is not set.

## ViewSetGroup

### *class* wagtail.admin.viewsets.base.ViewSetGroup

A container for grouping together multiple [`ViewSet`](#wagtail.admin.viewsets.base.ViewSet) instances.
Creates a menu item with a submenu for accessing the main URL for each instances.

For more information on how to use this class, see [使用 ViewSetGroup 组合多个 ViewSet](../extending/admin_views.html.md#using-base-viewsetgroup).

#### items *= ()*

要归组在一起的 [`ViewSet`](#wagtail.admin.viewsets.base.ViewSet) 类或实例的列表或元组。

#### menu_icon *= 'folder-open-inverse'*

The icon used for the menu item that appears in Wagtail's sidebar.

#### menu_label *= ''*

The displayed label used for the menu item.

#### menu_name *= ''*

The `name` argument passed to the `MenuItem` constructor, becoming the `name` attribute value for that instance.
This can be useful when manipulating the menu items in a custom menu hook, e.g. [construct_main_menu](hooks.html.md#construct-main-menu).
If unset, a slugified version of [`menu_label`](#wagtail.admin.viewsets.base.ViewSetGroup.menu_label) is used.

#### menu_order *= None*

An integer determining the order of the menu item, 0 being the first place.
If left unset, the order defaults to this item's position within its
containing group (such as a [`ViewSetGroup`](#wagtail.admin.viewsets.base.ViewSetGroup)),
if any. Otherwise, it is set to 8999, placing it as the last item before
Reports, whose order is 9000.

#### Versionchanged
在 8.0 版本发生变更: The value is now respected when the menu item is registered as part of a group.

#### menu_item_class

A `wagtail.admin.menu.MenuItem` subclass to be registered with a menu hook.

#### add_to_admin_menu *= True*

Register the menu item within the admin's main menu.

#### submenu_hook *= None*

The hook name for adding submenu items to this group.
Other registerables (e.g. `ViewSet`) with a matching [`menu_hook`](#wagtail.admin.viewsets.base.ViewSet.menu_hook)
or a `MenuItem` instance returned by a Wagtail hook of the same name
will be added to this group's menu.

#### get_menu_item(order=None)

Returns a `wagtail.admin.menu.MenuItem` instance to be registered
with the Wagtail admin.

The `order` parameter allows specifying the order of the menu item when
creating the menu item if the [`menu_order`](#wagtail.admin.viewsets.base.ViewSetGroup.menu_order) attribute is not set.

## ModelViewSet

### *class* wagtail.admin.viewsets.model.ModelViewSet(name=None, \*\*kwargs)

A viewset to allow listing, creating, editing and deleting model instances.

All attributes and methods from [`ViewSet`](#wagtail.admin.viewsets.base.ViewSet)
are available.

For more information on how to use this class, see [通用视图](../extending/generic_views.html.md#generic-views).

#### model

必需；该 viewset 要处理的模型类。除非通过 [`name`](#wagtail.admin.viewsets.base.ViewSet.name)、[`url_prefix`](#wagtail.admin.viewsets.base.ViewSet.url_prefix) 或
[`url_namespace`](#wagtail.admin.viewsets.base.ViewSet.url_namespace) 属性显式指定，否则 `model_name` 会被用作
URL 前缀和命名空间。

#### form_fields

应包含在创建 / 编辑表单中的模型字段名列表。

#### exclude_form_fields

用于替代 [`form_fields`](#wagtail.admin.viewsets.model.ModelViewSet.form_fields)，表示模型的所有字段中除这里列出的之外，都应出现在创建 / 编辑表单中。必须提供 `form_fields` 或 `exclude_form_fields` 之一（除非覆盖了 [`get_form_class()`](#wagtail.admin.viewsets.model.ModelViewSet.get_form_class)）。

#### get_form_class(for_update=False)

Returns the form class to use for the create / edit forms.

#### get_edit_handler()

Returns the appropriate edit handler for this `ModelViewSet` class.
It can be defined either on the model itself or on the `ModelViewSet`,
as the `edit_handler` or `panels` properties. If none of these are
defined, it will return `None` and the form will be constructed as
a Django form using [`get_form_class()`](#wagtail.admin.viewsets.model.ModelViewSet.get_form_class) (without using
[面板](../extending/forms.html.md#forms-panels-overview)).

#### get_permissions_to_register()

Returns a queryset of [`Permission`](https://docs.djangoproject.com/en/stable/ref/contrib/auth/#django.contrib.auth.models.Permission)
objects to be registered with the [register_permissions](hooks.html.md#register-permissions) hook. By
default, it returns all permissions for the model if
[`inspect_view_enabled`](#wagtail.admin.viewsets.model.ModelViewSet.inspect_view_enabled) is set to `True`. Otherwise, the "view"
permission is excluded.

#### permission_policy

The permission policy for the model.

#### Versionchanged
在 8.0 版本发生变更: This property is deprecated and will be removed in a future release.
Register the permission policy for the model via
[`wagtail.permissions.register_permission_policy()`](permissions.html.md#wagtail.permissions.register_permission_policy) instead.

#### menu_label

The displayed label used for the menu item.

默认为模型
[`verbose_name_plural`](https://docs.djangoproject.com/en/stable/ref/models/options/#django.db.models.Options.verbose_name_plural) 的首字母大写形式。

#### add_to_reference_index *= True*

Register the model to the reference index to track its usage.
For more details, see [管理引用索引](../advanced_topics/reference_index.html.md#managing-the-reference-index).

#### pk_path_converter

[Path converter](https://docs.djangoproject.com/en/stable/topics/http/urls/#path-converters) to use for
the model's primary key in URL patterns. Defaults to `"int"` for
`IntegerField`, `"uuid"` for `UUIDField`, and `"str"` for all
other types.

#### ordering *= UNDEFINED*

The default ordering to use for the index view.
Can be a string or a list/tuple in the same format as Django's
[`ordering`](https://docs.djangoproject.com/en/stable/ref/models/options/#django.db.models.Options.ordering).

#### sort_order_field *= UNDEFINED*

The name of an integer field on the model to use for ordering items
in the index view. If not set and the model has a `sort_order_field`
attribute (e.g.
[`Orderable.sort_order_field`](models.html.md#wagtail.models.Orderable.sort_order_field)),
that will be used instead. To disable reordering, set this to `None`.

#### list_per_page *= 20*

The number of items to display per page in the index view. Defaults to 20.

#### list_display *= UNDEFINED*

A list or tuple, where each item is either:

- The name of a field on the model;
- The name of a callable or property on the model that accepts a single
  parameter for the model instance; or
- An instance of the [`Column`](ui/tables.html.md#wagtail.admin.ui.tables.Column) class.

If the name refers to a database field, the ability to sort the listing
by the database column will be offered and the field's verbose name
will be used as the column header.

If the name refers to a callable or property, an `admin_order_field`
attribute can be defined on it to point to the database column for
sorting. A `short_description` attribute can also be defined on the
callable or property to be used as the column header.

该列表会被传给索引视图的 `list_display` 属性。如果未设置，则使用
索引视图的 `list_display` 属性，其默认值定义为包含
`"__str__"`、[`LocaleColumn()`](ui/tables.html.md#wagtail.admin.ui.tables.LocaleColumn)
和 [`UpdatedAtColumn()`](ui/tables.html.md#wagtail.admin.ui.tables.UpdatedAtColumn) 的列表。

注意，只有当模型可翻译时才会包含 `LocaleColumn`。

#### list_export *= UNDEFINED*

A list or tuple, where each item is the name of a field, an attribute,
or a single-argument callable on the model to be exported.

#### list_filter *= UNDEFINED*

A list or tuple, where each item is the name of model fields of type
`BooleanField`, `CharField`, `DateField`, `DateTimeField`,
`IntegerField` or `ForeignKey`.
Alternatively, it can also be a dictionary that maps a field name to a
list of lookup expressions.
This will be passed as django-filter's `FilterSet.Meta.fields`
attribute. See
[its documentation](https://django-filter.readthedocs.io/en/stable/guide/usage.html#generating-filters-with-meta-fields)
for more details.
If `filterset_class` is set, this attribute will be ignored.

#### filterset_class *= UNDEFINED*

A subclass of `wagtail.admin.filters.WagtailFilterSet`, which is a
subclass of [django_filters.FilterSet](https://django-filter.readthedocs.io/en/stable/ref/filterset.html).
This will be passed to the `filterset_class` attribute of the index view.

#### export_headings *= UNDEFINED*

A dictionary of export column heading overrides in the format
`{field_name: heading}`.

#### export_filename

The base file name for the exported listing, without extensions.

#### search_fields

The fields to use for the search in the index view.
If set to `None` and [`search_backend_name`](#wagtail.admin.viewsets.model.ModelViewSet.search_backend_name) is set to use a Wagtail search backend,
the `search_fields` attribute of the model will be used instead.

#### search_backend_name

The name of the Wagtail search backend to use for the search in the index view.
If set to a falsy value, the search will fall back to use Django's QuerySet API.

#### copy_view_enabled *= True*

Whether to enable the copy view. Defaults to `True`.

#### inspect_view_enabled *= False*

Whether to enable the inspect view. Defaults to `False`.

#### inspect_view_fields *= []*

The model fields or attributes to display in the inspect view.

If the field has a corresponding [`get_FOO_display()`](https://docs.djangoproject.com/en/stable/ref/models/instances/#django.db.models.Model.get_FOO_display)
method on the model, the method's return value will be used instead.

If you have `wagtail.images` installed, and the field's value is an instance of
`wagtail.images.models.AbstractImage`, a thumbnail of that image will be rendered.

If you have `wagtail.documents` installed, and the field's value is an instance of
`wagtail.docs.models.AbstractDocument`, a link to that document will be rendered,
along with the document title, file extension and size.

#### inspect_view_fields_exclude *= []*

The fields to exclude from the inspect view.

#### index_view_class *= <class 'wagtail.admin.views.generic.models.IndexView'>*

The view class to use for the index view; must be a subclass of `wagtail.admin.views.generic.IndexView`.

#### add_view_class *= <class 'wagtail.admin.views.generic.models.CreateView'>*

The view class to use for the create view; must be a subclass of `wagtail.admin.views.generic.CreateView`.

#### edit_view_class *= <class 'wagtail.admin.views.generic.models.EditView'>*

The view class to use for the edit view; must be a subclass of `wagtail.admin.views.generic.EditView`.

#### delete_view_class *= <class 'wagtail.admin.views.generic.models.DeleteView'>*

The view class to use for the delete view; must be a subclass of `wagtail.admin.views.generic.DeleteView`.

#### usage_view_class *= <class 'wagtail.admin.views.generic.usage.UsageView'>*

The view class to use for the usage view; must be a subclass of `wagtail.admin.views.generic.usage.UsageView`.

#### history_view_class *= <class 'wagtail.admin.views.generic.history.HistoryView'>*

The view class to use for the history view; must be a subclass of `wagtail.admin.views.generic.history.HistoryView`.

#### copy_view_class *= <class 'wagtail.admin.views.generic.models.CopyView'>*

The view class to use for the copy view; must be a subclass of `wagtail.admin.views.generic.CopyView`.

#### inspect_view_class *= <class 'wagtail.admin.views.generic.models.InspectView'>*

The view class to use for the inspect view; must be a subclass of `wagtail.admin.views.generic.InspectView`.

#### template_prefix *= ''*

The prefix of template names to look for when rendering the admin views.

#### index_template_name

A template to be used when rendering `index_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, an `index.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`index_view_class.template_name` will be used.

#### index_results_template_name

A template to be used when rendering `index_results_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, a `index_results.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`index_view_class.results_template_name` will be used.

#### create_template_name

A template to be used when rendering `add_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, a `create.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`add_view_class.template_name` will be used.

#### edit_template_name

A template to be used when rendering `edit_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, an `edit.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`edit_view_class.template_name` will be used.

#### delete_template_name

A template to be used when rendering `delete_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, a `confirm_delete.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`delete_view_class.template_name` will be used.

#### history_template_name

A template to be used when rendering `history_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, a `history.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`history_view_class.template_name` will be used.

#### inspect_template_name

A template to be used when rendering `inspect_view`.

Default: if [`template_prefix`](#wagtail.admin.viewsets.model.ModelViewSet.template_prefix) is specified, an `inspect.html`
template in the prefix directory and its `{app_label}/{model_name}/`
or `{app_label}/` subdirectories will be used. Otherwise, the
`inspect_view_class.template_name` will be used.

## ModelViewSetGroup

### *class* wagtail.admin.viewsets.model.ModelViewSetGroup

A container for grouping together multiple
[`ModelViewSet`](#wagtail.admin.viewsets.model.ModelViewSet) instances.

All attributes and methods from
[`ViewSetGroup`](#wagtail.admin.viewsets.base.ViewSetGroup) are available.

#### menu_label

The displayed label used for the menu item.

如果未设置，默认为第一个 viewset 中模型的
[`app_label`](https://docs.djangoproject.com/en/stable/ref/models/options/#django.db.models.Options.app_label) 的首字母大写形式。

## ChooserViewSet

### *class* wagtail.admin.viewsets.chooser.ChooserViewSet(\*args, \*\*kwargs)

A viewset that creates a chooser modal interface for choosing model instances.

#### model

必需；该 viewset 要处理的模型类。

#### icon *= 'snippet'*

The icon to use in the header of the chooser modal, and on the chooser widget

#### permission_policy *= UNDEFINED*

The permission policy for the model.

#### Versionchanged
在 8.0 版本发生变更: This property is deprecated and will be removed in a future release.
Register the permission policy for the model via
[`wagtail.permissions.register_permission_policy()`](permissions.html.md#wagtail.permissions.register_permission_policy) instead.

#### choose_one_text *= 'Choose'*

Label for the 'choose' button in the chooser widget when choosing an initial item

#### page_title *= None*

Title text for the chooser modal (defaults to the same as `choose_one_text`)\`

#### choose_another_text *= 'Choose another'*

Label for the 'choose' button in the chooser widget, when an item has already been chosen

#### edit_item_text *= 'Edit'*

Label for the 'edit' button in the chooser widget

#### per_page *= UNDEFINED*

Number of results to show per page

#### preserve_url_parameters *= ['multiple']*

A list of URL query parameters that should be passed on unmodified as part of any links or
form submissions within the chooser modal workflow.

#### url_filter_parameters *= []*

A list of URL query parameters that, if present in the url, should be applied as filters to the queryset.
(These should also be listed in preserve_url_parameters.)

#### choose_view_class *= <class 'wagtail.admin.views.generic.chooser.ChooseView'>*

The view class to use for the overall chooser modal; must be a subclass of `wagtail.admin.views.generic.chooser.ChooseView`.

#### choose_results_view_class *= <class 'wagtail.admin.views.generic.chooser.ChooseResultsView'>*

The view class used to render just the results panel within the chooser modal; must be a subclass of `wagtail.admin.views.generic.chooser.ChooseResultsView`.

#### chosen_view_class *= <class 'wagtail.admin.views.generic.chooser.ChosenView'>*

The view class used after an item has been chosen; must be a subclass of `wagtail.admin.views.generic.chooser.ChosenView`.

#### chosen_multiple_view_class *= <class 'wagtail.admin.views.generic.chooser.ChosenMultipleView'>*

The view class used after multiple items have been chosen; must be a subclass of `wagtail.admin.views.generic.chooser.ChosenMultipleView`.

#### create_view_class *= <class 'wagtail.admin.views.generic.chooser.CreateView'>*

The view class used to handle submissions of the 'create' form; must be a subclass of `wagtail.admin.views.generic.chooser.CreateView`.

#### base_widget_class *= <class 'wagtail.admin.widgets.chooser.BaseChooser'>*

The base Widget class that the chooser widget will be derived from.

#### widget_class

Returns the form widget class for this chooser.

#### widget_telepath_adapter_class *= None*

The adapter class used to map the widget class to its JavaScript implementation - see [表单组件的客户端 API](streamfield/widget_api.html.md#streamfield-widget-api).
Only required if the chooser uses custom JavaScript code.

#### register_widget *= True*

Defaults to True; if False, the chooser widget will not automatically be registered for use in admin forms.

#### base_block_class *= <class 'wagtail.blocks.field_block.ChooserBlock'>*

The base ChooserBlock class that the StreamField chooser block will be derived from.

#### get_block_class(name=None, module_path=None)

Returns a StreamField ChooserBlock class using this chooser.

* **参数:**
  * **name** -- Name to give to the class; defaults to the model name with "ChooserBlock" appended
  * **module_path** -- The dotted path of the module where the class can be imported from; used when
    deconstructing the block definition for migration files.

#### creation_form_class *= None*

Form class to use for the form in the "Create" tab of the modal.

#### form_fields *= None*

List of model fields that should be included in the creation form, if creation_form_class is not specified.

#### exclude_form_fields *= None*

List of model fields that should be excluded from the creation form, if creation_form_class.
If none of `creation_form_class`, `form_fields` or `exclude_form_fields` are specified, the "Create" tab will be omitted.

#### create_action_label *= 'Create'*

Label for the submit button on the 'create' form

#### create_action_clicked_label *= None*

Alternative text to display on the submit button after it has been clicked

#### creation_tab_label *= None*

Label for the 'create' tab in the chooser modal (defaults to the same as create_action_label)

#### search_tab_label *= 'Search'*

Label for the 'search' tab in the chooser modal

#### get_object_list()

返回可供选择的对象的 queryset。默认返回 `model` 的所有实例。

## SnippetViewSet

### *class* wagtail.snippets.views.snippets.SnippetViewSet(\*\*kwargs)

A viewset that instantiates the admin views for snippets.

All attributes and methods from
[`ModelViewSet`](#wagtail.admin.viewsets.model.ModelViewSet) are available.

For more information on how to use this class,
see [定制 Snippet 的管理视图](../topics/snippets/customizing.html.md#wagtailsnippets-custom-admin-views).

#### model *= None*

The model class to be registered as a snippet with this viewset.

#### chooser_per_page *= 10*

The number of items to display in the chooser view. Defaults to 10.

#### admin_url_namespace *= None*

The URL namespace to use for the admin views.
If left unset, `wagtailsnippets_{app_label}_{model_name}` is used instead.

**Deprecated** - the preferred attribute to customise is [`url_namespace`](#wagtail.admin.viewsets.base.ViewSet.url_namespace).

#### base_url_path *= None*

The base URL path to use for the admin views.
If left unset, `snippets/{app_label}/{model_name}` is used instead.

**Deprecated** - the preferred attribute to customise is [`url_prefix`](#wagtail.admin.viewsets.base.ViewSet.url_prefix).

#### chooser_admin_url_namespace *= None*

The URL namespace to use for the chooser admin views.
If left unset, `wagtailsnippetchoosers_{app_label}_{model_name}` is used instead.

#### chooser_base_url_path *= None*

The base URL path to use for the chooser admin views.
If left unset, `snippets/choose/{app_label}/{model_name}` is used instead.

#### index_view_class *= <class 'wagtail.snippets.views.snippets.IndexView'>*

The view class to use for the index view; must be a subclass of `wagtail.snippets.views.snippets.IndexView`.

#### add_view_class *= <class 'wagtail.snippets.views.snippets.CreateView'>*

The view class to use for the create view; must be a subclass of `wagtail.snippets.views.snippets.CreateView`.

#### edit_view_class *= <class 'wagtail.snippets.views.snippets.EditView'>*

The view class to use for the edit view; must be a subclass of `wagtail.snippets.views.snippets.EditView`.

#### delete_view_class *= <class 'wagtail.snippets.views.snippets.DeleteView'>*

The view class to use for the delete view; must be a subclass of `wagtail.snippets.views.snippets.DeleteView`.

#### usage_view_class *= <class 'wagtail.snippets.views.snippets.UsageView'>*

The view class to use for the usage view; must be a subclass of `wagtail.snippets.views.snippets.UsageView`.

#### history_view_class *= <class 'wagtail.snippets.views.snippets.HistoryView'>*

The view class to use for the history view; must be a subclass of `wagtail.snippets.views.snippets.HistoryView`.

#### copy_view_class *= <class 'wagtail.snippets.views.snippets.CopyView'>*

The view class to use for the copy view; must be a subclass of `wagtail.snippet.views.snippets.CopyView`.

#### inspect_view_class *= <class 'wagtail.snippets.views.snippets.InspectView'>*

The view class to use for the inspect view; must be a subclass of `wagtail.snippets.views.snippets.InspectView`.

#### revisions_view_class *= <class 'wagtail.snippets.views.snippets.PreviewRevisionView'>*

The view class to use for previewing revisions; must be a subclass of `wagtail.snippets.views.snippets.PreviewRevisionView`.

#### revisions_revert_view_class

The view class to use for reverting to a previous revision.

By default, this class is generated by combining the edit view with
`wagtail.admin.views.generic.mixins.RevisionsRevertMixin`. As a result,
this class must be a subclass of `wagtail.snippets.views.snippets.EditView`
and must handle the reversion correctly.

#### revisions_compare_view_class *= <class 'wagtail.snippets.views.snippets.RevisionsCompareView'>*

The view class to use for comparing revisions; must be a subclass of `wagtail.snippets.views.snippets.RevisionsCompareView`.

#### revisions_unschedule_view_class *= <class 'wagtail.snippets.views.snippets.RevisionsUnscheduleView'>*

The view class to use for unscheduling revisions; must be a subclass of `wagtail.snippets.views.snippets.RevisionsUnscheduleView`.

#### unpublish_view_class *= <class 'wagtail.snippets.views.snippets.UnpublishView'>*

The view class to use for unpublishing a snippet; must be a subclass of `wagtail.snippets.views.snippets.UnpublishView`.

#### preview_on_add_view_class *= <class 'wagtail.snippets.views.snippets.PreviewOnCreateView'>*

The view class to use for previewing on the create view; must be a subclass of `wagtail.snippets.views.snippets.PreviewOnCreateView`.

#### preview_on_edit_view_class *= <class 'wagtail.snippets.views.snippets.PreviewOnEditView'>*

The view class to use for previewing on the edit view; must be a subclass of `wagtail.snippets.views.snippets.PreviewOnEditView`.

#### lock_view_class *= <class 'wagtail.snippets.views.snippets.LockView'>*

The view class to use for locking a snippet; must be a subclass of `wagtail.snippets.views.snippets.LockView`.

#### unlock_view_class *= <class 'wagtail.snippets.views.snippets.UnlockView'>*

The view class to use for unlocking a snippet; must be a subclass of `wagtail.snippets.views.snippets.UnlockView`.

#### chooser_viewset_class *= <class 'wagtail.snippets.views.chooser.SnippetChooserViewSet'>*

The ViewSet class to use for the chooser views; must be a subclass of `wagtail.snippets.views.chooser.SnippetChooserViewSet`.

#### get_queryset(request)

Returns a QuerySet of all model instances to be shown on the index view.
If `None` is returned (the default), the logic in
`index_view.get_base_queryset()` will be used instead.

#### get_edit_handler()

Like [`ModelViewSet.get_edit_handler()`](#wagtail.admin.viewsets.model.ModelViewSet.get_edit_handler),
but falls back to extracting panel definitions from the model class
if no edit handler is defined.

#### get_index_template()

Returns a template to be used when rendering `index_view`. If a
template is specified by the `index_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define an `index_template_name` property.

#### get_index_results_template()

Returns a template to be used when rendering `index_results_view`. If a
template is specified by the `index_results_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define an `index_results_template_name` property.

#### get_create_template()

Returns a template to be used when rendering `add_view`. If a
template is specified by the `create_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define a `create_template_name` property.

#### get_edit_template()

Returns a template to be used when rendering `edit_view`. If a
template is specified by the `edit_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define an `edit_template_name` property.

#### get_delete_template()

Returns a template to be used when rendering `delete_view`. If a
template is specified by the `delete_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define a `delete_template_name` property.

#### get_history_template()

Returns a template to be used when rendering `history_view`. If a
template is specified by the `history_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define a `history_template_name` property.

#### get_inspect_template()

Returns a template to be used when rendering `inspect_view`. If a
template is specified by the `inspect_template_name` attribute, that will
be used. Otherwise, a list of preferred template names are returned.

**Deprecated** - the preferred way to customise this is to define an `inspect_template_name` property.

#### get_admin_url_namespace()

Returns the URL namespace for the admin URLs for this model.

**Deprecated** - the preferred way to customise this is to define a `url_namespace` property.

#### get_admin_base_path()

Returns the base path for the admin URLs for this model.
The returned string must not begin or end with a slash.

**Deprecated** - the preferred way to customise this is to define a `url_prefix` property.

#### get_chooser_admin_url_namespace()

Returns the URL namespace for the chooser admin URLs for this model.

#### get_chooser_admin_base_path()

Returns the base path for the chooser admin URLs for this model.
The returned string must not begin or end with a slash.

## SnippetChooserViewSet

### *class* wagtail.snippets.views.chooser.SnippetChooserViewSet(\*args, \*\*kwargs)

A [`ChooserViewSet`](#wagtail.admin.viewsets.chooser.ChooserViewSet) subclass with
support for additional snippet-specific features.

All attributes and methods from `ChooserViewSet` are available.

#### choose_view_class *= <class 'wagtail.snippets.views.chooser.ChooseView'>*

The view class to use for the overall chooser modal;
must be a subclass of `wagtail.snippets.views.chooser.ChooseView`.

#### choose_results_view_class *= <class 'wagtail.snippets.views.chooser.ChooseResultsView'>*

The view class used to render just the results panel within the chooser modal;
must be a subclass of `wagtail.snippets.views.chooser.ChooseResultsView`.

#### chosen_view_class *= <class 'wagtail.snippets.views.chooser.SnippetChosenView'>*

The view class used after an item has been chosen;
must be a subclass of `wagtail.snippets.views.chooser.SnippetChosenView`.

#### chosen_multiple_view_class *= <class 'wagtail.snippets.views.chooser.SnippetChosenMultipleView'>*

The view class used after multiple items have been chosen;
must be a subclass of `wagtail.snippets.views.chooser.SnippetChosenMultipleView`.

#### create_view_class *= <class 'wagtail.snippets.views.chooser.SnippetCreateView'>*

The view class used to handle submissions of the 'create' form;
must be a subclass of `wagtail.snippets.views.chooser.SnippetCreateView`.

#### base_widget_class *= <class 'wagtail.snippets.widgets.AdminSnippetChooser'>*

The base Widget class that the chooser widget will be derived from.

#### widget_class

Returns the form widget class for this chooser.

## SnippetViewSetGroup

### *class* wagtail.snippets.views.snippets.SnippetViewSetGroup

A container for grouping together multiple
[`SnippetViewSet`](#wagtail.snippets.views.snippets.SnippetViewSet) instances.

All attributes and methods from
[`ModelViewSetGroup`](#wagtail.admin.viewsets.model.ModelViewSetGroup) are available.

## PageListingViewSet

### *class* wagtail.admin.viewsets.pages.PageListingViewSet(name=None, \*\*kwargs)

A viewset to present a flat listing of all pages of a specific type.
All attributes and methods from [`ViewSet`](#wagtail.admin.viewsets.base.ViewSet)
are available.
For more information on how to use this class, see [创建自定义的扁平页面列表](../advanced_topics/customization/custom_page_listings.html.md#custom-flat-page-listings).

#### model *= <class 'wagtail.models.Page'>*

Required; the page model class that this viewset will work with.

#### index_view_class *= <class 'wagtail.admin.views.pages.listing.IndexView'>*

The view class to use for the index view; must be a subclass of `wagtail.admin.views.pages.listing.IndexView`.

#### choose_parent_view_class *= <class 'wagtail.admin.views.pages.choose_parent.ChooseParentView'>*

The view class to use for choosing the parent page when creating a new page of this page type.

#### list_display *= UNDEFINED*

A list or tuple, where each item is either:

- The name of a field on the model;
- The name of a callable or property on the model that accepts a single
  parameter for the model instance; or
- An instance of the [`Column`](ui/tables.html.md#wagtail.admin.ui.tables.Column) class.

If the name refers to a database field, the ability to sort the listing
by the database column will be offered and the field's verbose name
will be used as the column header.

If the name refers to a callable or property, an `admin_order_field`
attribute can be defined on it to point to the database column for
sorting. A `short_description` attribute can also be defined on the
callable or property to be used as the column header.

#### columns *= [<wagtail.admin.ui.tables.pages.BulkActionsColumn: bulk_actions>, <wagtail.admin.ui.tables.pages.PageTitleColumn: title>, <wagtail.admin.ui.tables.pages.ParentPageColumn: parent>, <wagtail.admin.ui.tables.DateColumn: latest_revision_created_at>, <wagtail.admin.ui.tables.pages.PageStatusColumn: status>]*

A list of [`Column`](ui/tables.html.md#wagtail.admin.ui.tables.Column) instances for the columns in the listing.
This takes priority over [`list_display`](#wagtail.admin.viewsets.pages.PageListingViewSet.list_display) if both are defined.

#### list_filter *= UNDEFINED*

A list or tuple, where each item is the name of model fields of type
`BooleanField`, `CharField`, `DateField`, `DateTimeField`,
`IntegerField` or `ForeignKey`.
Alternatively, it can also be a dictionary that maps a field name to a
list of lookup expressions.
This will be passed as django-filter's `FilterSet.Meta.fields`
attribute. See
[its documentation](https://django-filter.readthedocs.io/en/stable/guide/usage.html#generating-filters-with-meta-fields)
for more details.
If `filterset_class` is set, this attribute will be ignored.

#### filterset_class *= <class 'wagtail.admin.views.pages.listing.GenericPageFilterSet'>*

A subclass of `wagtail.admin.filters.WagtailFilterSet`, which is a
subclass of [django_filters.FilterSet](https://django-filter.readthedocs.io/en/stable/ref/filterset.html).
This will be passed to the `filterset_class` attribute of the index view.

#### list_per_page *= UNDEFINED*

The number of items to display per page in the index view.

#### list_export *= UNDEFINED*

A list or tuple, where each item is the name of a field, an attribute,
or a single-argument callable on the model to be exported.

#### export_headings *= UNDEFINED*

A dictionary of export column heading overrides in the format
`{field_name: heading}`.

#### export_filename

The base file name for the exported listing, without extensions.

## PageViewSet

### *class* wagtail.admin.viewsets.pages.PageViewSet(name=None, \*\*kwargs)

A viewset to define the views for pages of a specific type.
For more information on how to use this class, see [定制默认页面列表](../advanced_topics/customization/custom_page_listings.html.md#custom-default-page-listings).

#### model *= <class 'wagtail.models.Page'>*

Required; the page model class that this viewset will work with.

#### parent_models

The parent page models to associate in the main page explorer, so this
viewset's listing view will be used when exploring the parent page
models' children. This allows displaying, filtering, and ordering on
fields of a specific child page model in the explorer.

By default, if the main [`model`](#wagtail.admin.viewsets.pages.PageViewSet.model)
[`parent_page_types`](models.html.md#wagtail.models.AbstractPage.parent_page_types) is defined, this will be
every model in the list that also defines
[`subpage_types`](models.html.md#wagtail.models.AbstractPage.subpage_types) with only this viewset's
model (or its subclasses). In other words, this will apply to this
viewset model's parents that only allow this viewset model (or its
subclasses) as children.

Otherwise, the viewset's listing view customizations will not have any
effect.

#### list_display *= UNDEFINED*

A list or tuple, where each item is either:

- The name of a field on the model;
- The name of a callable or property on the model that accepts a single
  parameter for the model instance; or
- An instance of the [`Column`](ui/tables.html.md#wagtail.admin.ui.tables.Column) class.

If the name refers to a database field, the ability to sort the listing
by the database column will be offered and the field's verbose name
will be used as the column header.

If the name refers to a callable or property, an `admin_order_field`
attribute can be defined on it to point to the database column for
sorting. A `short_description` attribute can also be defined on the
callable or property to be used as the column header.

#### columns *= [<wagtail.admin.ui.tables.pages.BulkActionsColumn: bulk_actions>, <wagtail.admin.ui.tables.pages.PageTitleColumn: title>, <wagtail.admin.ui.tables.pages.ParentPageColumn: parent>, <wagtail.admin.ui.tables.DateColumn: latest_revision_created_at>, <wagtail.admin.ui.tables.pages.PageTypeColumn: type>, <wagtail.admin.ui.tables.pages.PageStatusColumn: status>]*

A list of [`Column`](ui/tables.html.md#wagtail.admin.ui.tables.Column) instances for the columns in the listing.
This takes priority over [`list_display`](#wagtail.admin.viewsets.pages.PageViewSet.list_display) if both are defined.

#### list_filter *= UNDEFINED*

A list or tuple, where each item is the name of model fields of type
`BooleanField`, `CharField`, `DateField`, `DateTimeField`,
`IntegerField` or `ForeignKey`.
Alternatively, it can also be a dictionary that maps a field name to a
list of lookup expressions.
This will be passed as django-filter's `FilterSet.Meta.fields`
attribute. See
[its documentation](https://django-filter.readthedocs.io/en/stable/guide/usage.html#generating-filters-with-meta-fields)
for more details.
If `filterset_class` is set, this attribute will be ignored.

#### filterset_class *= <class 'wagtail.admin.views.pages.listing.GenericPageFilterSet'>*

A subclass of `wagtail.admin.filters.WagtailFilterSet`, which is a
subclass of [django_filters.FilterSet](https://django-filter.readthedocs.io/en/stable/ref/filterset.html).
This will be passed to the `filterset_class` attribute of the index view.

#### list_per_page *= UNDEFINED*

The number of items to display per page in the index view.

#### list_export *= UNDEFINED*

A list or tuple, where each item is the name of a field, an attribute,
or a single-argument callable on the model to be exported.

#### export_headings *= UNDEFINED*

A dictionary of export column heading overrides in the format
`{field_name: heading}`.

#### export_filename

The base file name for the exported listing, without extensions.

#### choose_parent_view_class *= <class 'wagtail.admin.views.pages.choose_parent.GenericChooseParentView'>*

The view class to use for choosing the parent page when creating a new page of this page type;
must be a subclass of `wagtail.admin.views.pages.choose_parent.GenericChooseParentView`.

#### content_type_use_view_class *= <class 'wagtail.admin.views.pages.usage.ContentTypeUseView'>*

The view class to use for the flat per-page-type index view; must be a subclass of
`wagtail.admin.views.pages.usage.ContentTypeUseView`.

#### add_subpage_view_class *= <class 'wagtail.admin.views.pages.create.AddSubpageView'>*

The view class to use for the add subpage view; must be a subclass of
`wagtail.admin.views.pages.create.AddSubpageView`.

#### add_view_class *= <class 'wagtail.admin.views.pages.create.CreateView'>*

The view class to use for the create view; must be a subclass of
`wagtail.admin.views.pages.create.CreateView`.

#### collect_workflow_action_data_view_class *= <class 'wagtail.admin.views.pages.workflow.CollectWorkflowActionDataView'>*

The view class to use for performing a workflow action that returns the
validated data in the response; must be a subclass of
`wagtail.admin.views.pages.workflow.CollectWorkflowActionDataView`.

#### confirm_workflow_cancellation_view_class *= <class 'wagtail.admin.views.pages.workflow.ConfirmWorkflowCancellationView'>*

The view class to use for confirming the cancellation of a workflow;
must be a subclass of
`wagtail.admin.views.pages.workflow.ConfirmWorkflowCancellationView`.

#### convert_alias_view_class *= <class 'wagtail.admin.views.pages.convert_alias.ConvertAliasView'>*

The view class to use for the convert alias view; must be a subclass of
`wagtail.admin.views.pages.convert_alias.ConvertAliasView`.

#### copy_view_class *= <class 'wagtail.admin.views.pages.copy.CopyView'>*

The view class to use for the copy view; must be a subclass of
`wagtail.admin.views.pages.copy.CopyView`.

#### edit_view_class *= <class 'wagtail.admin.views.pages.edit.EditView'>*

The view class to use for the edit view; must be a subclass of
`wagtail.admin.views.pages.edit.EditView`.

#### delete_view_class *= <class 'wagtail.admin.views.pages.delete.DeleteView'>*

The view class to use for the delete view; must be a subclass of
`wagtail.admin.views.pages.delete.DeleteView`.

#### history_view_class *= <class 'wagtail.admin.views.pages.history.PageHistoryView'>*

The view class to use for the history view; must be a subclass of
`wagtail.admin.views.pages.history.PageHistoryView`.

#### index_view_class *= <class 'wagtail.admin.views.pages.listing.ExplorableIndexView'>*

The view class to use for the index view; must be a subclass of
`wagtail.admin.views.pages.listing.ExplorableIndexView`.

#### lock_view_class *= <class 'wagtail.admin.views.pages.lock.LockView'>*

The view class to use for locking a page; must be a subclass of
`wagtail.admin.views.pages.lock.LockView`.

#### move_view_class *= <class 'wagtail.admin.views.pages.move.MoveChooseDestinationView'>*

The view class to use for choosing a destination when moving a page;
must be a subclass of
`wagtail.admin.views.pages.move.MoveChooseDestinationView`.

#### move_confirm_view_class *= <class 'wagtail.admin.views.pages.move.MoveConfirmView'>*

The view class to use for the confirmation view when moving a page;
must be a subclass of
`wagtail.admin.views.pages.move.MoveConfirmView`.

#### unlock_view_class *= <class 'wagtail.admin.views.pages.lock.UnlockView'>*

The view class to use for unlocking a page; must be a subclass of
`wagtail.admin.views.pages.lock.UnlockView`.

#### preview_on_add_view_class *= <class 'wagtail.admin.views.pages.preview.PreviewOnCreateView'>*

The view class to use for the preview on create view; must be a subclass of
`wagtail.admin.views.pages.preview.PreviewOnCreateView`.

#### preview_on_edit_view_class *= <class 'wagtail.admin.views.pages.preview.PreviewOnEditView'>*

The view class to use for the preview on edit view; must be a subclass of
`wagtail.admin.views.pages.preview.PreviewOnEditView`.

#### revisions_view_class *= <class 'wagtail.admin.views.pages.revisions.RevisionsView'>*

The view class to use for previewing revisions; must be a subclass of
`wagtail.admin.views.pages.revisions.RevisionsView`.

#### revisions_compare_view_class *= <class 'wagtail.admin.views.pages.revisions.RevisionsCompareView'>*

The view class to use for comparing revisions; must be a subclass of
`wagtail.admin.views.pages.revisions.RevisionsCompareView`.

#### revisions_revert_view_class *= <class 'wagtail.admin.views.pages.revisions.RevisionsRevertView'>*

The view class to use for the revisions revert view; must be a subclass of
`wagtail.admin.views.pages.revisions.RevisionsRevertView`.

#### revisions_unschedule_view_class *= <class 'wagtail.admin.views.pages.revisions.RevisionsUnscheduleView'>*

The view class to use for unscheduling revisions; must be a subclass of
`wagtail.admin.views.pages.revisions.RevisionsUnscheduleView`.

#### search_view_class *= <class 'wagtail.admin.views.pages.search.SearchView'>*

The view class to use for the page search view; must be a subclass of
`wagtail.admin.views.pages.search.SearchView`.

This is only used by the base `Page` model's viewset.

#### set_page_position_view_class *= <class 'wagtail.admin.views.pages.ordering.SetPagePositionView'>*

The view class to use for the set page position view; must be a subclass of
`wagtail.admin.views.pages.ordering.SetPagePositionView`.

#### set_privacy_view_class *= <class 'wagtail.admin.views.page_privacy.SetPrivacyView'>*

The view class to use for the set privacy view; must be a subclass of
`wagtail.admin.views.page_privacy.SetPrivacyView`.

#### unpublish_view_class *= <class 'wagtail.admin.views.pages.unpublish.UnpublishView'>*

The view class to use for unpublishing a page; must be a subclass of
`wagtail.admin.views.pages.unpublish.UnpublishView`.

#### usage_view_class *= <class 'wagtail.admin.views.pages.usage.UsageView'>*

The view class to use for the usage view; must be a subclass of
`wagtail.admin.views.pages.usage.UsageView`.

#### view_draft_view_class *= <class 'wagtail.admin.views.pages.preview.ViewDraftView'>*

The view class to use for the view draft view; must be a subclass of
`wagtail.admin.views.pages.preview.ViewDraftView`.

#### workflow_action_view_class *= <class 'wagtail.admin.views.pages.workflow.WorkflowActionView'>*

The view class to use for performing a workflow action; must be a subclass of
`wagtail.admin.views.pages.workflow.WorkflowActionView`.

#### workflow_history_view_class *= <class 'wagtail.admin.views.pages.history.WorkflowHistoryView'>*

The view class to use for the workflow history view; must be a subclass of
`wagtail.admin.views.pages.history.WorkflowHistoryView`.

#### workflow_history_detail_view_class *= <class 'wagtail.admin.views.pages.history.WorkflowHistoryDetailView'>*

The view class to use for the workflow history detail view; must be a subclass of
`wagtail.admin.views.pages.history.WorkflowHistoryDetailView`.

#### workflow_preview_view_class *= <class 'wagtail.admin.views.pages.workflow.PreviewRevisionForTaskView'>*

The view class to use for previewing a revision for a specific task;
must be a subclass of
`wagtail.admin.views.pages.workflow.PreviewRevisionForTaskView`.
