Viewsets¶
Viewsets are Wagtail’s mechanism for defining a group of related admin views with shared properties, as a single unit. See Generic views.
ViewSet¶
- class wagtail.admin.viewsets.base.ViewSet(name, **kwargs)¶
Defines a viewset to be registered with the Wagtail admin.
- Parameters
name – A name for this viewset, used as the URL namespace.
url_prefix – A URL path element, given as a string, that the URLs for this viewset will be found under. Defaults to the same as
name
.
All other keyword arguments will be set as attributes on the instance.
- 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.
ModelViewSet¶
- class wagtail.admin.viewsets.model.ModelViewSet(name, **kwargs)¶
A viewset to allow listing, creating, editing and deleting model instances.
- model¶
Required; the model class that this viewset will work with.
- form_fields¶
A list of model field names that should be included in the create / edit forms.
- 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. Eitherform_fields
orexclude_form_fields
must be supplied (unlessget_form_class
is being overridden).- get_form_class(for_update=False)¶
Returns the form class to use for the create / edit forms.
- icon = ''¶
The icon to use to represent the model within this viewset.
- 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
.
ChooserViewSet¶
- class wagtail.admin.viewsets.chooser.ChooserViewSet(*args, **kwargs)¶
A viewset that creates a chooser modal interface for choosing model instances.
- model¶
Required; the model class that this viewset will work with.
- icon = 'snippet'¶
The icon to use in the header of the chooser modal, and on the chooser widget
- 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 = 'Change'¶
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 = 10¶
Number of results to show per page
- 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
.
- 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 Form widget client-side 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.
- Parameters
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
orexclude_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