2024-10-22 05:23:07 +00:00
# Model reference
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2024-10-29 08:21:58 +00:00
.. module:: wagtail.models
2022-07-20 15:49:25 +00:00
```
2015-05-18 10:36:40 +00:00
2024-10-29 08:21:58 +00:00
This document contains reference information for the model classes inside the `wagtail.models` module.
2015-05-29 11:53:48 +00:00
2022-07-20 15:49:25 +00:00
(page_model_ref)=
2016-03-06 04:14:51 +00:00
2022-07-20 15:49:25 +00:00
## `Page`
2015-05-18 13:44:18 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: Page
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
.. attribute:: title
(text)
2015-05-18 10:36:40 +00:00
2015-05-18 13:44:18 +00:00
Human-readable title of the page.
2015-05-18 10:36:40 +00:00
2017-07-06 20:21:25 +00:00
.. attribute:: draft_title
(text)
Human-readable title of the page, incorporating any changes that have been made in a draft edit (in contrast to the ``title`` field, which for published pages will be the title as it exists in the current published version).
2015-05-18 15:30:55 +00:00
.. attribute:: slug
(text)
2015-05-29 11:53:48 +00:00
This is used for constructing the page's URL.
2015-05-18 15:30:55 +00:00
For example: ``http://domain.com/blog/[my-slug]/``
.. attribute:: content_type
(foreign key to ``django.contrib.contenttypes.models.ContentType``)
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this page.
2015-05-18 13:44:18 +00:00
2015-05-18 15:30:55 +00:00
.. attribute:: live
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
(boolean)
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
A boolean that is set to ``True`` if the page is published.
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
Note: this field defaults to ``True`` meaning that any pages that are created programmatically will be published by default.
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
.. attribute:: has_unpublished_changes
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
(boolean)
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
A boolean that is set to ``True`` when the page is either in draft or published with draft changes.
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
.. attribute:: owner
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
(foreign key to user model)
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
A foreign key to the user that created the page.
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
.. attribute:: first_published_at
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
(date/time)
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +00:00
The date/time when the page was first published.
2015-05-18 13:44:18 +00:00
2017-06-02 09:58:34 +00:00
.. attribute:: last_published_at
(date/time)
The date/time when the page was last published.
2015-05-18 15:30:55 +00:00
.. attribute:: seo_title
2015-05-18 13:44:18 +00:00
2015-05-18 15:30:55 +00:00
(text)
2015-05-18 13:44:18 +00:00
2015-05-18 15:30:55 +00:00
Alternate SEO-crafted title, for use in the page's ``< title > `` HTML tag.
2015-05-18 13:44:18 +00:00
2015-05-18 15:30:55 +00:00
.. attribute:: search_description
2015-05-18 13:44:18 +00:00
2015-05-18 15:30:55 +00:00
(text)
2015-05-18 13:44:18 +00:00
2015-05-18 15:30:55 +00:00
SEO-crafted description of the content, used for search indexing. This is also suitable for the page's ``< meta name = "description" > `` HTML tag.
.. attribute:: show_in_menus
(boolean)
2022-03-04 14:34:21 +00:00
Toggles whether the page should be included in site-wide menus, and is shown in the ``promote_panels`` within the Page editor.
2015-05-18 15:30:55 +00:00
2022-03-04 14:34:21 +00:00
Wagtail does not include any menu implementation by default, which means that this field will not do anything in the front facing content unless built that way in a specific Wagtail installation.
2022-03-17 14:38:02 +00:00
However, this is used by the :meth:`~wagtail.query.PageQuerySet.in_menu` QuerySet filter to make it easier to query for pages that use this field.
2018-02-06 14:10:45 +00:00
2017-05-26 14:09:15 +00:00
Defaults to ``False`` and can be overridden on the model with ``show_in_menus_default = True``.
2018-02-06 14:10:45 +00:00
.. note::
To set the global default for all pages, set ``Page.show_in_menus_default = True`` once where you first import the ``Page`` model.
2019-10-16 13:26:04 +00:00
.. attribute:: locked
(boolean)
2019-10-28 11:16:54 +00:00
When set to ``True``, the Wagtail editor will not allow any users to edit
2019-10-16 13:26:04 +00:00
the content of the page.
2019-10-28 11:16:54 +00:00
If ``locked_by`` is also set, only that user can edit the page.
2019-10-16 13:26:04 +00:00
.. attribute:: locked_by
2020-12-02 10:40:25 +00:00
(foreign key to user model)
2019-10-16 13:26:04 +00:00
The user who has currently locked the page. Only this user can edit the page.
2020-01-02 09:41:42 +00:00
If this is ``None`` when ``locked`` is ``True``, nobody can edit the page.
2019-10-16 13:26:04 +00:00
.. attribute:: locked_at
(date/time)
The date/time when the page was locked.
2015-05-18 10:36:40 +00:00
2020-09-28 11:04:51 +00:00
.. attribute:: alias_of
(foreign key to another page)
If set, this page is an alias of the page referenced in this field.
2020-10-19 17:40:58 +00:00
.. attribute:: locale
(foreign key to Locale)
This foreign key links to the ``Locale`` object that represents the page language.
.. attribute:: translation_key
(uuid)
A UUID that is shared between translations of a page. These are randomly generated
when a new page is created and copied when a translation of a page is made.
2024-10-21 14:40:00 +00:00
A ``translation_key`` value can only be used on one page in each locale.
2022-07-20 15:49:25 +00:00
```
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
In addition to the model fields provided, `Page` has many properties and methods that you may wish to reference, use, or override in creating your own models.
2017-11-11 10:28:58 +00:00
2022-07-20 15:49:25 +00:00
```{note}
2024-11-04 14:50:58 +00:00
See also [django-treebeard ](inv:treebeard:std:doc#index )'s [node API ](inv:treebeard:std:doc#api ). ``Page`` is a subclass of [materialized path tree ](inv:treebeard:std:doc#mp_tree ) nodes.
2022-07-20 15:49:25 +00:00
```
2017-11-11 10:28:58 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: Page
2024-07-22 15:21:26 +00:00
:no-index:
2015-02-19 16:53:24 +00:00
2020-12-13 22:21:17 +00:00
.. automethod:: get_specific
2015-02-19 16:53:24 +00:00
.. autoattribute:: specific
2020-12-13 22:21:17 +00:00
.. autoattribute:: specific_deferred
2015-02-19 16:53:24 +00:00
.. autoattribute:: specific_class
2020-07-07 15:29:06 +00:00
.. autoattribute:: cached_content_type
2022-05-04 12:54:04 +00:00
.. autoattribute:: page_type_display_name
2018-05-18 14:26:06 +00:00
.. automethod:: get_url
2015-02-19 16:53:24 +00:00
2021-08-03 14:31:54 +00:00
.. automethod:: get_full_url
2015-02-19 16:53:24 +00:00
.. autoattribute:: full_url
2016-01-21 17:09:35 +00:00
.. automethod:: relative_url
.. automethod:: get_site
.. automethod:: get_url_parts
2015-02-19 16:53:24 +00:00
.. automethod:: route
.. automethod:: serve
2024-01-24 12:18:21 +00:00
2022-11-01 14:30:15 +00:00
.. automethod:: route_for_request
2024-01-24 12:18:21 +00:00
2022-11-01 14:30:15 +00:00
.. automethod:: find_for_request
2015-02-19 16:53:24 +00:00
2020-05-01 18:01:02 +00:00
.. autoattribute:: context_object_name
Custom name for page instance in page's ``Context``.
2015-02-19 16:53:24 +00:00
.. automethod:: get_context
.. automethod:: get_template
2016-09-28 13:55:38 +00:00
.. automethod:: get_admin_display_title
2024-11-20 00:15:36 +00:00
.. autoattribute:: allowed_http_methods
When customizing this attribute, developers are encouraged to use values from Python's built-in ``http.HTTPMethod`` enum in the list, as it is more robust, and makes use of values that already exist in memory. For example:
.. code-block:: python
from http import HTTPMethod
class MyPage(Page):
allowed_http_methods = [HTTPMethod.GET, HTTPMethod.OPTIONS]
The ``http.HTTPMethod`` enum wasn't added until Python 3.11, so if your project uses an older version of Python, you can use uppercase strings instead. For example:
.. code-block:: python
class MyPage(Page):
allowed_http_methods = ["GET", "OPTIONS"]
.. automethod:: check_request_method
.. automethod:: handle_options_request
2015-02-19 16:53:24 +00:00
.. autoattribute:: preview_modes
2024-10-14 12:30:52 +00:00
.. autoattribute:: default_preview_mode
2024-10-18 15:33:29 +00:00
2024-10-14 12:30:52 +00:00
.. autoattribute:: preview_sizes
.. autoattribute:: default_preview_size
2024-10-18 15:33:29 +00:00
2015-02-19 16:53:24 +00:00
.. automethod:: serve_preview
2017-01-26 16:44:53 +00:00
.. automethod:: get_parent
2024-01-22 13:02:24 +00:00
.. automethod:: get_children
2015-02-19 16:53:24 +00:00
.. automethod:: get_ancestors
.. automethod:: get_descendants
.. automethod:: get_siblings
2020-10-19 17:40:58 +00:00
.. automethod:: get_translations
.. automethod:: get_translation
.. automethod:: get_translation_or_none
.. automethod:: has_translation
.. automethod:: copy_for_translation
2023-11-29 15:56:01 +00:00
.. method:: get_admin_default_ordering
Returns the default sort order for child pages to be sorted in viewing the admin pages index and not seeing search results.
The following sort orders are available:
- ``'content_type'``
- ``'-content_type'``
- ``'latest_revision_created_at'``
- ``'-latest_revision_created_at'``
- ``'live'``
- ``'-live'``
- ``'ord'``
- ``'title'``
- ``'-title'``
For example to make a page sort by title for all the child pages only if there are < 20 pages .
.. code-block:: python
class BreadsIndexPage(Page):
def get_admin_default_ordering(self):
if Page.objects.child_of(self).count() < 20:
return 'title'
return self.admin_default_ordering
.. attribute:: admin_default_ordering
An attribute version for the method ``get_admin_default_ordering()``, defaults to ``'-latest_revision_created_at'``.
2020-10-19 17:40:58 +00:00
.. autoattribute:: localized
.. autoattribute:: localized_draft
2015-02-19 16:53:24 +00:00
.. attribute:: search_fields
2015-10-10 02:17:54 +00:00
2015-02-19 16:53:24 +00:00
A list of fields to be indexed by the search engine. See Search docs :ref:`wagtailsearch_indexing_fields`
.. attribute:: subpage_types
2020-06-16 10:23:51 +00:00
A list of page models which can be created as children of this page type. For example, a ``BlogIndex`` page might allow a ``BlogPage`` as a child, but not a ``JobPage``:
2015-02-19 16:53:24 +00:00
.. code-block:: python
class BlogIndex(Page):
subpage_types = ['mysite.BlogPage', 'mysite.BlogArchivePage']
2015-10-10 02:17:54 +00:00
2020-06-16 10:23:51 +00:00
The creation of child pages can be blocked altogether for a given page by setting its subpage_types attribute to an empty array:
2015-10-10 02:17:54 +00:00
2015-02-21 10:05:41 +00:00
.. code-block:: python
class BlogPage(Page):
subpage_types = []
2015-10-10 02:17:54 +00:00
2015-02-21 10:05:41 +00:00
.. attribute:: parent_page_types
2020-06-16 10:23:51 +00:00
A list of page models which are allowed as parent page types. For example, a ``BlogPage`` may only allow itself to be created below the ``BlogIndex`` page:
2015-02-21 10:05:41 +00:00
.. code-block:: python
class BlogPage(Page):
parent_page_types = ['mysite.BlogIndexPage']
2015-10-10 02:17:54 +00:00
Pages can block themselves from being created at all by setting parent_page_types to an empty array (this is useful for creating unique pages that should only be created once):
2015-02-21 10:05:41 +00:00
.. code-block:: python
class HiddenPage(Page):
parent_page_types = []
2015-02-19 16:53:24 +00:00
2022-07-18 12:00:02 +00:00
To allow for a page to be only created under the root page (for example for ``HomePage`` models) set the ``parent_page_type`` to ``['wagtailcore.Page']``.
2021-09-03 23:21:33 +00:00
.. code-block:: python
class HomePage(Page):
parent_page_types = ['wagtailcore.Page']
2015-10-10 02:17:54 +00:00
.. automethod:: can_exist_under
.. automethod:: can_create_at
.. automethod:: can_move_to
2022-01-07 13:10:53 +00:00
.. automethod:: get_route_paths
2015-02-19 16:53:24 +00:00
.. attribute:: password_required_template
2024-01-24 12:18:21 +00:00
Defines which template file should be used to render the login form for Protected pages using this model. This overrides the default, defined using ``WAGTAIL_PASSWORD_REQUIRED_TEMPLATE`` in your settings. See :ref:`private_pages`
2015-05-18 10:36:40 +00:00
2015-08-21 10:09:36 +00:00
.. attribute:: is_creatable
2024-01-21 05:54:37 +00:00
Controls if this page can be created through the Wagtail administration. Defaults to ``True``, and is not inherited by subclasses. This is useful when using :ref:`multi-table inheritance < django:meta-and-multi-table-inheritance > `, to stop the base model from being created as an actual page.
2015-08-21 10:09:36 +00:00
2018-10-27 10:19:20 +00:00
.. attribute:: max_count
Controls the maximum number of pages of this type that can be created through the Wagtail administration interface. This is useful when needing "allow at most 3 of these pages to exist", or for singleton pages.
2019-03-15 11:32:54 +00:00
.. attribute:: max_count_per_parent
Controls the maximum number of pages of this type that can be created under any one parent page.
2024-07-18 16:17:42 +00:00
.. attribute:: private_page_options
Controls what privacy options are available for the page type.
The following options are available:
- ``'password'`` - Can restrict to use a shared password
- ``'groups'`` - Can restrict to users in specific groups
- ``'login'`` - Can restrict to logged in users
.. code-block:: python
class BreadPage(Page):
...
2024-08-28 10:35:10 +00:00
# default
2024-07-18 16:17:42 +00:00
private_page_options = ['password', 'groups', 'login']
# disable shared password
private_page_options = ['groups', 'login']
# only shared password
private_page_options = ['password']
# no privacy options for this page model
private_page_options = []
2017-11-01 12:37:14 +00:00
.. attribute:: exclude_fields_in_copy
An array of field names that will not be included when a Page is copied.
2024-10-21 14:40:00 +00:00
Useful when you have relations that do not use ``ClusterableModel`` or should not be copied.
2017-11-01 12:37:14 +00:00
.. code-block:: python
class BlogPage(Page):
exclude_fields_in_copy = ['special_relation', 'custom_uuid']
The following fields will always be excluded in a copy - `['id', 'path', 'depth', 'numchild', 'url_path', 'path']` .
2016-05-03 07:28:33 +00:00
.. attribute:: base_form_class
2024-01-27 08:45:05 +00:00
The form class is used as a base for editing Pages of this type in the Wagtail page editor.
This attribute can be set on a model to customize the Page editor form.
2017-11-17 10:44:34 +00:00
Forms must be a subclass of :class:`~wagtail.admin.forms.WagtailAdminPageForm`.
2016-05-03 07:28:33 +00:00
See :ref:`custom_edit_handler_forms` for more information.
2019-04-04 10:39:38 +00:00
.. automethod:: with_content_json
2020-02-15 05:04:57 +00:00
.. automethod:: save
2024-06-13 12:44:13 +00:00
.. automethod:: copy
2020-09-28 11:06:22 +00:00
.. automethod:: create_alias
2020-09-28 11:07:39 +00:00
.. automethod:: update_aliases
2022-11-03 17:35:17 +00:00
.. automethod:: get_cache_key_components
.. autoattribute:: cache_key
2022-07-20 15:49:25 +00:00
```
2020-02-27 14:37:03 +00:00
2022-07-20 15:49:25 +00:00
(site_model_ref)=
2016-10-01 19:04:46 +00:00
2022-07-20 15:49:25 +00:00
## `Site`
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
The `Site` model is useful for multi-site installations as it allows an administrator to configure which part of the tree to use for each hostname that the server responds on.
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
The {meth}`~wagtail.models.Site.find_for_request` function returns the Site object that will handle the given HTTP request.
2020-01-24 12:21:17 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: Site
2015-05-18 15:30:55 +00:00
.. attribute:: hostname
(text)
2024-01-27 08:45:05 +00:00
This is the hostname of the site, excluding the scheme, port, and path.
2015-05-18 15:30:55 +00:00
For example: ``www.mysite.com``
.. note::
If you're looking for how to get the root url of a site, use the :attr:`~Site.root_url` attribute.
.. attribute:: port
(number)
This is the port number that the site responds on.
2016-01-13 12:49:20 +00:00
.. attribute:: site_name
(text - optional)
A human-readable name for the site. This is not used by Wagtail itself, but is suitable for use on the site front-end, such as in ``< title > `` elements.
For example: ``Rod's World of Birds``
2015-05-18 15:30:55 +00:00
.. attribute:: root_page
2022-03-17 14:38:02 +00:00
(foreign key to :class:`~wagtail.models.Page`)
2015-05-18 15:30:55 +00:00
This is a link to the root page of the site. This page will be what appears at the ``/`` URL on the site and would usually be a homepage.
.. attribute:: is_default_site
(boolean)
This is set to ``True`` if the site is the default. Only one site can be the default.
The default site is used as a fallback in situations where a site with the required hostname/port couldn't be found.
2022-07-20 15:49:25 +00:00
```
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2015-07-07 08:18:22 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: Site
2024-07-22 15:21:26 +00:00
:no-index:
2015-05-18 15:30:55 +00:00
2015-05-18 10:36:40 +00:00
.. automethod:: find_for_request
.. autoattribute:: root_url
2015-05-18 15:30:55 +00:00
This returns the URL of the site. It is calculated from the :attr:`~Site.hostname` and the :attr:`~Site.port` fields.
The scheme part of the URL is calculated based on value of the :attr:`~Site.port` field:
2021-02-05 11:02:05 +00:00
- 80 = ``http://``
- 443 = ``https://``
2022-07-18 12:00:02 +00:00
- Everything else will use the ``http://`` scheme and the port will be appended to the end of the hostname (for example ``http://mysite.com:8000/``)
2015-05-18 15:30:55 +00:00
2015-05-18 10:36:40 +00:00
.. automethod:: get_site_root_paths
2022-07-20 15:49:25 +00:00
```
2015-05-18 10:36:40 +00:00
2022-10-29 11:27:27 +00:00
(locale_model_ref)=
2022-08-15 03:43:55 +00:00
## `Locale`
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
The `Locale` model defines the set of languages and/or locales that can be used on a site.
2024-06-10 14:12:29 +00:00
Each `Locale` record corresponds to a "language code" defined in the {ref}`wagtail_content_languages_setting` setting.
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
Wagtail will initially set up one `Locale` to act as the default language for all existing content.
This first locale will automatically pick the value from `WAGTAIL_CONTENT_LANGUAGES` that most closely matches the site primary language code defined in `LANGUAGE_CODE` .
If the primary language code is changed later, Wagtail will **not** automatically create a new `Locale` record or update an existing one.
2020-10-19 17:40:58 +00:00
2024-01-27 08:45:05 +00:00
Before internationalization is enabled, all pages use this primary `Locale` record.
This is to satisfy the database constraints and make it easier to switch internationalization on at a later date.
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
### Changing `WAGTAIL_CONTENT_LANGUAGES`
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
Languages can be added or removed from `WAGTAIL_CONTENT_LANGUAGES` over time.
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
Before removing an option from `WAGTAIL_CONTENT_LANGUAGES` , it's important that the `Locale`
2024-01-27 08:45:05 +00:00
record is updated to use a different content language or is deleted.
2022-07-20 15:49:25 +00:00
Any `Locale` instances that have invalid content languages are automatically filtered out from all
2020-10-19 17:40:58 +00:00
database queries making them unable to be edited or viewed.
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-10-19 17:40:58 +00:00
.. class:: Locale
.. autoattribute:: language_code
.. automethod:: get_default
.. automethod:: get_active
2022-10-29 11:27:27 +00:00
.. autoattribute:: language_name
.. autoattribute:: language_name_local
.. autoattribute:: language_name_localized
.. autoattribute:: is_default
.. autoattribute:: is_active
.. autoattribute:: is_bidi
2020-10-19 17:40:58 +00:00
.. automethod:: get_display_name
2022-07-20 15:49:25 +00:00
```
2020-10-19 17:40:58 +00:00
2022-08-15 03:43:55 +00:00
## `TranslatableMixin`
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
`TranslatableMixin` is an abstract model that can be added to any non-page Django model to make it translatable.
2020-10-19 17:40:58 +00:00
Pages already include this mixin, so there is no need to add it.
2022-08-15 03:43:55 +00:00
### Database fields
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-10-19 17:40:58 +00:00
.. class:: TranslatableMixin
.. attribute:: locale
2024-06-07 13:20:11 +00:00
(Foreign Key to :class:`wagtail.models.Locale`)
2020-10-19 17:40:58 +00:00
For pages, this defaults to the locale of the parent page.
.. attribute:: translation_key
(uuid)
A UUID that is randomly generated whenever a new model instance is created.
This is shared with all translations of that instance so can be used for querying translations.
2022-08-15 03:43:55 +00:00
```
2024-01-27 08:45:05 +00:00
The `translation_key` and `locale` fields have a unique key constraint to prevent the object from being translated into a language more than once.
2023-10-22 15:05:02 +00:00
```{note}
This is currently enforced via {attr}`~django.db.models.Options.unique_together` in `TranslatableMixin.Meta` , but may be replaced with a {class}`~django.db.models.UniqueConstraint` in `TranslatableMixin.Meta.constraints` in the future.
2023-12-06 03:00:06 +00:00
If your model defines a [`Meta` class ](inv:django#ref/models/options ) (either with a new definition or inheriting `TranslatableMixin.Meta` explicitly), be mindful when setting `unique_together` or {attr}`~django.db.models.Options.constraints`. Ensure that there is either a `unique_together` or a `UniqueConstraint` (not both) on `translation_key` and `locale` . There is a system check for this.
2023-10-22 15:05:02 +00:00
```
2022-08-15 03:43:55 +00:00
### Methods and properties
```{eval-rst}
.. class:: TranslatableMixin
2024-07-22 15:21:26 +00:00
:no-index:
2020-10-19 17:40:58 +00:00
.. automethod:: get_translations
.. automethod:: get_translation
.. automethod:: get_translation_or_none
.. automethod:: has_translation
.. automethod:: copy_for_translation
.. automethod:: get_translation_model
.. autoattribute:: localized
2022-07-20 15:49:25 +00:00
```
2020-10-19 17:40:58 +00:00
2022-08-15 10:38:45 +00:00
## `PreviewableMixin`
`PreviewableMixin` is a mixin class that can be added to any non-page Django model to allow previewing its instances.
Pages already include this mixin, so there is no need to add it.
### Methods and properties
```{eval-rst}
.. class:: PreviewableMixin
.. autoattribute:: preview_modes
.. autoattribute:: default_preview_mode
2024-10-18 15:33:29 +00:00
2024-10-14 12:30:52 +00:00
.. autoattribute:: preview_sizes
.. autoattribute:: default_preview_size
2022-08-15 10:38:45 +00:00
.. automethod:: is_previewable
.. automethod:: get_preview_context
.. automethod:: get_preview_template
.. automethod:: serve_preview
```
2022-08-15 10:49:13 +00:00
## `RevisionMixin`
`RevisionMixin` is an abstract model that can be added to any non-page Django model to allow saving revisions of its instances.
Pages already include this mixin, so there is no need to add it.
### Database fields
```{eval-rst}
.. class:: RevisionMixin
.. attribute:: latest_revision
(foreign key to :class:`~wagtail.models.Revision`)
2024-01-27 08:45:05 +00:00
This points to the latest revision created for the object. This reference is stored in the database for performance optimization.
2022-08-15 10:49:13 +00:00
```
### Methods and properties
```{eval-rst}
.. class:: RevisionMixin
2024-07-22 15:21:26 +00:00
:no-index:
2022-08-15 10:49:13 +00:00
.. autoattribute:: revisions
.. automethod:: save_revision
.. automethod:: get_latest_revision_as_object
.. automethod:: with_content_json
```
2022-08-15 07:02:24 +00:00
## `DraftStateMixin`
`DraftStateMixin` is an abstract model that can be added to any non-page Django model to allow its instances to have unpublished changes.
This mixin requires {class}`~wagtail.models.RevisionMixin` to be applied. Pages already include this mixin, so there is no need to add it.
### Database fields
```{eval-rst}
.. class:: DraftStateMixin
.. attribute:: live
(boolean)
A boolean that is set to ``True`` if the object is published.
Note: this field defaults to ``True`` meaning that any objects that are created programmatically will be published by default.
.. attribute:: live_revision
(foreign key to :class:`~wagtail.models.Revision`)
This points to the revision that is currently live.
.. attribute:: has_unpublished_changes
(boolean)
A boolean that is set to ``True`` when the object is either in draft or published with draft changes.
.. attribute:: first_published_at
(date/time)
The date/time when the object was first published.
.. attribute:: last_published_at
(date/time)
The date/time when the object was last published.
```
### Methods and properties
```{eval-rst}
.. class:: DraftStateMixin
2024-07-22 15:21:26 +00:00
:no-index:
2022-08-15 07:02:24 +00:00
.. automethod:: publish
.. automethod:: unpublish
.. automethod:: with_content_json
```
2022-12-09 12:33:45 +00:00
## `LockableMixin`
`LockableMixin` is an abstract model that can be added to any non-page Django model to allow its instances to be locked.
2023-04-21 11:18:28 +00:00
Pages already include this mixin, so there is no need to add it. See [](wagtailsnippets_locking_snippets) for more details.
2022-12-09 12:33:45 +00:00
### Database fields
```{eval-rst}
.. class:: LockableMixin
.. attribute:: locked
(boolean)
A boolean that is set to ``True`` if the object is locked.
.. attribute:: locked_at
(date/time)
The date/time when the object was locked.
.. attribute:: locked_by
(foreign key to user model)
The user who locked the object.
```
### Methods and properties
```{eval-rst}
.. class:: LockableMixin
2024-07-22 15:21:26 +00:00
:no-index:
2022-12-09 12:33:45 +00:00
.. automethod:: get_lock
.. automethod:: with_content_json
```
2023-01-12 17:11:41 +00:00
## `WorkflowMixin`
`WorkflowMixin` is a mixin class that can be added to any non-page Django model to allow its instances to be submitted to workflows.
2023-04-21 11:18:28 +00:00
This mixin requires {class}`~wagtail.models.RevisionMixin` and {class}`~wagtail.models.DraftStateMixin` to be applied. Pages already include this mixin, so there is no need to add it. See [](wagtailsnippets_enabling_workflows) for more details.
2023-01-12 17:11:41 +00:00
### Methods and properties
```{eval-rst}
.. class:: WorkflowMixin
.. automethod:: get_default_workflow
.. autoattribute:: has_workflow
.. automethod:: get_workflow
.. autoattribute:: workflow_states
.. autoattribute:: workflow_in_progress
.. autoattribute:: current_workflow_state
.. autoattribute:: current_workflow_task_state
.. autoattribute:: current_workflow_task
```
2022-07-20 15:49:25 +00:00
(revision_model_ref)=
2020-10-19 17:40:58 +00:00
2022-07-20 15:49:25 +00:00
## `Revision`
2016-03-06 04:14:51 +00:00
2022-07-20 15:49:25 +00:00
Every time a page is edited, a new `Revision` is created and saved to the database. It can be used to find the full history of all changes that have been made to a page and it also provides a place for new changes to be kept before going live.
2015-05-18 10:36:40 +00:00
2022-08-15 10:47:59 +00:00
- Revisions can be created from any instance of {class}`~wagtail.models.RevisionMixin` by calling its {meth}`~RevisionMixin.save_revision` method.
- The content of the page is JSON-serialisable and stored in the {attr}`~Revision.content` field.
- You can retrieve a `Revision` as an instance of the object's model by calling the {meth}`~Revision.as_object` method.
2015-05-18 15:30:55 +00:00
2023-10-19 10:52:29 +00:00
You can use the [`purge_revisions` ](purge_revisions ) command to delete old revisions that are no longer in use.
2022-07-20 15:49:25 +00:00
### Database fields
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2022-05-17 10:46:30 +00:00
.. class:: Revision
2015-05-18 15:30:55 +00:00
2022-05-25 23:08:30 +00:00
.. attribute:: content_object
(generic foreign key)
2022-08-15 10:47:59 +00:00
The object this revision belongs to. For page revisions, the object is an instance of the specific class.
2022-05-25 23:08:30 +00:00
2022-05-17 10:46:30 +00:00
.. attribute:: content_type
2015-05-18 15:30:55 +00:00
2022-05-17 10:46:30 +00:00
(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
2022-08-15 10:47:59 +00:00
The content type of the object this revision belongs to. For page revisions, this means the content type of the specific page type.
2022-05-17 10:46:30 +00:00
.. attribute:: base_content_type
(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
2022-08-15 10:47:59 +00:00
The base content type of the object this revision belongs to. For page revisions, this means the content type of the :class:`~wagtail.models.Page` model.
2022-05-17 10:46:30 +00:00
.. attribute:: object_id
(string)
2022-08-15 10:47:59 +00:00
The primary key of the object this revision belongs to.
2015-05-18 15:30:55 +00:00
.. attribute:: created_at
(date/time)
2022-08-15 10:47:59 +00:00
The time the revision was created.
2015-05-18 15:30:55 +00:00
.. attribute:: user
(foreign key to user model)
2022-08-15 10:47:59 +00:00
The user that created the revision.
2015-05-18 15:30:55 +00:00
2022-02-22 12:38:51 +00:00
.. attribute:: content
2015-05-18 15:30:55 +00:00
2022-02-22 12:38:51 +00:00
(dict)
2015-05-18 15:30:55 +00:00
2022-08-15 10:47:59 +00:00
The JSON content for the object at the time the revision was created.
2022-07-20 15:49:25 +00:00
```
2022-02-22 12:38:51 +00:00
2022-07-20 15:49:25 +00:00
### Managers
2015-07-07 08:18:22 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2022-05-17 10:46:30 +00:00
.. class:: Revision
2024-07-22 15:21:26 +00:00
:no-index:
2015-05-18 15:30:55 +00:00
.. attribute:: objects
2024-06-07 13:20:11 +00:00
This default manager is used to retrieve all of the ``Revision`` objects in the database. It also provides a ``wagtail.models.RevisionsManager.for_instance`` method that lets you query for revisions of a specific object.
2015-05-18 15:30:55 +00:00
Example:
.. code-block:: python
2022-05-17 10:46:30 +00:00
Revision.objects.all()
2022-05-25 23:08:30 +00:00
Revision.objects.for_instance(my_object)
2022-05-17 10:46:30 +00:00
.. attribute:: page_revisions
2022-05-25 23:08:30 +00:00
This manager extends the default manager and is used to retrieve all of the ``Revision`` objects that belong to pages.
2022-05-17 10:46:30 +00:00
Example:
.. code-block:: python
Revision.page_revisions.all()
2022-07-20 15:49:25 +00:00
```
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2015-07-07 08:18:22 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2022-05-17 10:46:30 +00:00
.. class:: Revision
2024-07-22 15:21:26 +00:00
:no-index:
2015-05-29 11:53:48 +00:00
2022-05-17 10:46:30 +00:00
.. automethod:: as_object
This method retrieves this revision as an instance of its object's specific class. If the revision belongs to a page, it will be an instance of the :class:`~wagtail.models.Page`'s specific subclass.
2015-05-18 10:36:40 +00:00
.. automethod:: is_latest_revision
2022-08-15 10:47:59 +00:00
Returns ``True`` if this revision is the object's latest revision.
2015-05-18 15:30:55 +00:00
2015-05-18 10:36:40 +00:00
.. automethod:: publish
2022-05-17 10:46:30 +00:00
Calling this will copy the content of this revision into the live object. If the object is in draft, it will be published.
2022-05-25 23:08:30 +00:00
.. autoattribute:: base_content_object
2022-05-17 10:46:30 +00:00
This property returns the object this revision belongs to as an instance of the base class.
2022-07-20 15:49:25 +00:00
```
2022-05-17 10:46:30 +00:00
2022-07-20 15:49:25 +00:00
## `GroupPagePermission`
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: GroupPagePermission
2015-05-18 15:30:55 +00:00
.. attribute:: group
(foreign key to ``django.contrib.auth.models.Group``)
.. attribute:: page
2022-03-17 14:38:02 +00:00
(foreign key to :class:`~wagtail.models.Page`)
2022-07-20 15:49:25 +00:00
```
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
## `PageViewRestriction`
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: PageViewRestriction
2015-05-18 15:30:55 +00:00
.. attribute:: page
2022-03-17 14:38:02 +00:00
(foreign key to :class:`~wagtail.models.Page`)
2015-05-18 15:30:55 +00:00
.. attribute:: password
(text)
2024-05-01 18:21:38 +00:00
.. attribute:: restriction_type
(text)
Options: none, password, groups, login
2022-07-20 15:49:25 +00:00
```
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
## `Orderable` (abstract)
2015-05-18 10:36:40 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2015-05-18 15:30:55 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2015-07-07 08:18:22 +00:00
.. class:: Orderable
2015-05-18 15:30:55 +00:00
.. attribute:: sort_order
(number)
2022-07-20 15:49:25 +00:00
```
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
## `Workflow`
2020-02-24 15:52:19 +00:00
2024-01-27 08:45:05 +00:00
Workflows represent sequences of tasks that must be approved for an action to be performed on an object - typically publication.
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: Workflow
.. attribute:: name
(text)
Human-readable name of the workflow.
.. attribute:: active
(boolean)
2024-10-21 14:40:00 +00:00
Whether or not the workflow is active. Active workflows can be added to pages and snippets, and started. Inactive workflows cannot.
2022-07-20 15:49:25 +00:00
```
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: Workflow
2024-07-22 15:21:26 +00:00
:no-index:
2020-02-24 15:52:19 +00:00
.. automethod:: start
.. autoattribute:: tasks
.. automethod:: deactivate
2020-07-16 09:45:00 +00:00
.. automethod:: all_pages
2022-07-20 15:49:25 +00:00
```
2020-07-16 09:45:00 +00:00
2022-07-20 15:49:25 +00:00
## `WorkflowState`
2020-02-24 15:52:19 +00:00
2023-01-19 14:05:42 +00:00
Workflow states represent the status of a started workflow on an object.
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: WorkflowState
2023-01-19 14:05:42 +00:00
.. attribute:: content_object
(generic foreign key)
The object on which the workflow has been started. For page workflows, the object is an instance of the base ``Page`` model.
.. attribute:: content_type
(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
2020-02-24 15:52:19 +00:00
2023-01-19 14:05:42 +00:00
The content type of the object this workflow state belongs to. For page workflows, this means the content type of the specific page type.
2020-02-24 15:52:19 +00:00
2023-01-19 14:05:42 +00:00
.. attribute:: base_content_type
(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
The base content type of the object this workflow state belongs to. For page workflows, this means the content type of the :class:`~wagtail.models.Page` model.
.. attribute:: object_id
(string)
The primary key of the object this revision belongs to.
2020-02-24 15:52:19 +00:00
.. attribute:: workflow
(foreign key to ``Workflow``)
2024-10-21 14:40:00 +00:00
The workflow whose state the ``WorkflowState`` represents.
2020-02-24 15:52:19 +00:00
.. attribute:: status
(text)
The current status of the workflow (options are ``WorkflowState.STATUS_CHOICES``)
.. attribute:: created_at
(date/time)
When this instance of ``WorkflowState`` was created - when the workflow was started
.. attribute:: requested_by
(foreign key to user model)
The user who started this workflow
.. attribute:: current_task_state
(foreign key to ``TaskState``)
The ``TaskState`` model for the task the workflow is currently at: either completing (if in progress) or the final task state (if finished)
2022-07-20 15:49:25 +00:00
```
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: WorkflowState
2024-07-22 15:21:26 +00:00
:no-index:
2020-02-24 15:52:19 +00:00
.. attribute:: STATUS_CHOICES
A tuple of the possible options for the ``status`` field, and their verbose names. Options are ``STATUS_IN_PROGRESS``, ``STATUS_APPROVED``,
2020-07-16 09:45:00 +00:00
``STATUS_CANCELLED`` and ``STATUS_NEEDS_CHANGES``.
2020-02-24 15:52:19 +00:00
.. automethod:: update
.. automethod:: get_next_task
.. automethod:: cancel
.. automethod:: finish
2020-07-16 09:45:00 +00:00
.. automethod:: resume
2020-02-24 15:52:19 +00:00
.. automethod:: copy_approved_task_states_to_revision
2020-02-27 14:37:03 +00:00
.. automethod:: all_tasks_with_status
.. automethod:: revisions
2022-07-20 15:49:25 +00:00
```
2020-02-27 14:37:03 +00:00
2022-07-20 15:49:25 +00:00
## `Task`
2020-02-24 15:52:19 +00:00
2024-01-27 08:45:05 +00:00
Tasks represent stages in a workflow that must be approved for the workflow to complete successfully.
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: Task
.. attribute:: name
(text)
Human-readable name of the task.
.. attribute:: active
(boolean)
Whether or not the task is active: active workflows can be added to workflows, and started. Inactive workflows cannot, and are skipped when in
an existing workflow.
.. attribute:: content_type
(foreign key to ``django.contrib.contenttypes.models.ContentType``)
A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this task.
2022-07-20 15:49:25 +00:00
```
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: Task
2024-07-22 15:21:26 +00:00
:no-index:
2020-02-24 15:52:19 +00:00
2020-07-16 09:45:00 +00:00
.. autoattribute:: workflows
.. autoattribute:: active_workflows
2020-02-24 15:52:19 +00:00
.. attribute:: task_state_class
The specific task state class to generate to store state information for this task. If not specified, this will be ``TaskState``.
.. automethod:: get_verbose_name
2020-07-17 22:11:02 +00:00
.. autoattribute:: specific
2020-02-24 15:52:19 +00:00
.. automethod:: start
.. automethod:: on_action
.. automethod:: user_can_access_editor
.. automethod:: user_can_lock
.. automethod:: user_can_unlock
2022-12-13 16:25:31 +00:00
.. automethod:: locked_for_user
2020-07-16 09:45:00 +00:00
2020-02-24 15:52:19 +00:00
.. automethod:: get_actions
.. automethod:: get_task_states_user_can_moderate
.. automethod:: deactivate
2020-07-16 09:45:00 +00:00
.. automethod:: get_form_for_action
.. automethod:: get_template_for_action
.. automethod:: get_description
2022-07-20 15:49:25 +00:00
```
2020-07-16 09:45:00 +00:00
2022-07-20 15:49:25 +00:00
## `TaskState`
2020-02-24 15:52:19 +00:00
2023-01-19 14:05:42 +00:00
Task states store state information about the progress of a task on a particular revision.
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: TaskState
.. attribute:: workflow_state
2023-01-19 14:05:42 +00:00
(foreign key to :class:`~wagtail.models.WorkflowState`)
2020-02-24 15:52:19 +00:00
The workflow state which started this task state.
2022-12-12 14:27:34 +00:00
.. attribute:: revision
2020-02-24 15:52:19 +00:00
2023-01-19 14:05:42 +00:00
(foreign key to :class:`~wagtail.models.Revision`)
2020-02-24 15:52:19 +00:00
2022-12-12 14:27:34 +00:00
The revision this task state was created on.
2020-02-24 15:52:19 +00:00
.. attribute:: task
2023-01-19 14:05:42 +00:00
(foreign key to :class:`~wagtail.models.Task`)
2020-02-24 15:52:19 +00:00
The task that this task state is storing state information for.
.. attribute:: status
(text)
The completion status of the task on this revision. Options are available in ``TaskState.STATUS_CHOICES``)
.. attribute:: content_type
(foreign key to ``django.contrib.contenttypes.models.ContentType``)
A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this task.
.. attribute:: started_at
(date/time)
When this task state was created.
.. attribute:: finished_at
(date/time)
2024-01-27 08:45:05 +00:00
When this task state was canceled, rejected, or approved.
2020-02-24 15:52:19 +00:00
2020-07-16 09:45:00 +00:00
.. attribute:: finished_by
(foreign key to user model)
2024-01-27 08:45:05 +00:00
The user who completed (canceled, rejected, approved) the task.
2020-07-16 09:45:00 +00:00
.. attribute:: comment
(text)
2024-01-27 08:45:05 +00:00
A text comment is typically added by a user when the task is completed.
2022-07-20 15:49:25 +00:00
```
2020-07-16 09:45:00 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: TaskState
2024-07-22 15:21:26 +00:00
:no-index:
2020-02-24 15:52:19 +00:00
.. attribute:: STATUS_CHOICES
A tuple of the possible options for the ``status`` field, and their verbose names. Options are ``STATUS_IN_PROGRESS``, ``STATUS_APPROVED``,
``STATUS_CANCELLED``, ``STATUS_REJECTED`` and ``STATUS_SKIPPED``.
.. attribute:: exclude_fields_in_copy
A list of fields not to copy when the ``TaskState.copy()`` method is called.
2020-07-17 22:11:02 +00:00
.. autoattribute:: specific
2020-02-24 15:52:19 +00:00
.. automethod:: approve
.. automethod:: reject
2020-07-17 22:11:02 +00:00
.. autoattribute:: task_type_started_at
2020-02-24 15:52:19 +00:00
.. automethod:: cancel
.. automethod:: copy
2020-07-16 09:45:00 +00:00
.. automethod:: get_comment
2022-07-20 15:49:25 +00:00
```
2020-07-16 09:45:00 +00:00
2022-07-20 15:49:25 +00:00
## `WorkflowTask`
2020-02-24 15:52:19 +00:00
Represents the ordering of a task in a specific workflow.
2022-07-20 15:49:25 +00:00
### Database fields
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: WorkflowTask
.. attribute:: workflow
(foreign key to ``Workflow``)
.. attribute:: task
(foreign key to ``Task``)
.. attribute:: sort_order
(number)
The ordering of the task in the workflow.
2022-07-20 15:49:25 +00:00
```
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
## `WorkflowPage`
2020-02-24 15:52:19 +00:00
Represents the assignment of a workflow to a page and its descendants.
2022-07-20 15:49:25 +00:00
### Database fields
2020-02-24 15:52:19 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-02-24 15:52:19 +00:00
.. class:: WorkflowPage
.. attribute:: workflow
2023-01-19 14:05:42 +00:00
(foreign key to :class:`~wagtail.models.Workflow`)
2020-02-24 15:52:19 +00:00
.. attribute:: page
2023-01-19 14:05:42 +00:00
(foreign key to :class:`~wagtail.models.Page`)
```
## `WorkflowContentType`
Represents the assignment of a workflow to a Django model.
### Database fields
```{eval-rst}
.. class:: WorkflowContentType
.. attribute:: workflow
(foreign key to :class:`~wagtail.models.Workflow`)
.. attribute:: content_type
(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
A foreign key to the ``ContentType`` object that represents the model that is assigned to the workflow.
2022-07-20 15:49:25 +00:00
```
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
## `BaseLogEntry`
2020-07-09 21:57:16 +00:00
An abstract base class that represents a record of an action performed on an object.
2022-07-20 15:49:25 +00:00
### Database fields
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-07-09 21:57:16 +00:00
.. class:: BaseLogEntry
.. attribute:: content_type
(foreign key to ``django.contrib.contenttypes.models.ContentType``)
A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this model.
.. attribute:: label
(text)
The object title at the time of the entry creation
2024-07-18 23:21:39 +00:00
Note: Wagtail will attempt to use ``get_admin_display_title`` or the string representation of the object passed to ``LogEntryManager.log_action``
2020-07-09 21:57:16 +00:00
.. attribute:: user
(foreign key to user model)
A foreign key to the user that triggered the action.
2022-05-06 07:28:58 +00:00
.. attribute:: revision
(foreign key to :class:`Revision`)
A foreign key to the current revision.
2022-02-22 04:38:21 +00:00
.. attribute:: data
2020-07-09 21:57:16 +00:00
2022-02-22 04:38:21 +00:00
(dict)
2020-07-09 21:57:16 +00:00
The JSON representation of any additional details for each action.
2024-01-27 08:45:05 +00:00
For example, source page id and title when copying from a page. Or workflow id/name and next step id/name on a workflow transition
2020-07-09 21:57:16 +00:00
.. attribute:: timestamp
(date/time)
The date/time when the entry was created.
.. attribute:: content_changed
(boolean)
2024-01-27 08:45:05 +00:00
A boolean that can be set to ``True`` when the content has changed.
2020-07-09 21:57:16 +00:00
.. attribute:: deleted
(boolean)
A boolean that can set to ``True`` when the object is deleted. Used to filter entries in the Site History report.
2022-07-20 15:49:25 +00:00
```
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
### Methods and properties
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-07-09 21:57:16 +00:00
.. class:: BaseLogEntry
2024-07-22 15:21:26 +00:00
:no-index:
2020-07-09 21:57:16 +00:00
2020-09-30 14:43:27 +00:00
.. autoattribute:: user_display_name
2020-07-09 21:57:16 +00:00
2020-07-17 22:11:02 +00:00
.. autoattribute:: comment
2020-07-09 21:57:16 +00:00
2020-07-17 22:11:02 +00:00
.. autoattribute:: object_verbose_name
2020-07-09 21:57:16 +00:00
.. automethod:: object_id
2022-07-20 15:49:25 +00:00
```
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
## `PageLogEntry`
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
Represents a record of an action performed on an {class}`Page`, subclasses {class}`BaseLogEntry`.
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
### Database fields
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2020-07-09 21:57:16 +00:00
.. class:: PageLogEntry
.. attribute:: page
(foreign key to :class:`Page`)
A foreign key to the page the action is performed on.
2022-07-20 15:49:25 +00:00
```
2020-07-09 21:57:16 +00:00
2022-07-20 15:49:25 +00:00
## `Comment`
2021-04-30 13:03:57 +00:00
Represents a comment on a page.
2022-07-20 15:49:25 +00:00
### Database fields
2021-04-30 13:03:57 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2021-04-30 13:03:57 +00:00
.. class:: Comment
.. attribute:: page
(parental key to :class:`Page`)
A parental key to the page the comment has been added to.
.. attribute:: user
(foreign key to user model)
A foreign key to the user who added this comment.
.. attribute:: text
(text)
The text content of the comment.
.. attribute:: contentpath
(text)
The path to the field or streamfield block the comment is attached to,
in the form ``field`` or ``field.streamfield_block_id``.
.. attribute:: position
(text)
An identifier for the position of the comment within its field. The format
used is determined by the field.
.. attribute:: created_at
(date/time)
The date/time when the comment was created.
.. attribute:: updated_at
(date/time)
The date/time when the comment was updated.
.. attribute:: revision_created
2022-05-17 10:46:30 +00:00
(foreign key to :class:`Revision`)
2021-04-30 13:03:57 +00:00
A foreign key to the revision on which the comment was created.
.. attribute:: resolved_at
(date/time)
The date/time when the comment was resolved, if any.
.. attribute:: resolved_by
(foreign key to user model)
A foreign key to the user who resolved this comment, if any.
2022-07-20 15:49:25 +00:00
```
2021-04-30 13:03:57 +00:00
2022-07-20 15:49:25 +00:00
## `CommentReply`
2021-04-30 13:03:57 +00:00
Represents a reply to a comment thread.
2022-07-20 15:49:25 +00:00
### Database fields
2021-04-30 13:03:57 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2021-04-30 13:03:57 +00:00
.. class:: CommentReply
.. attribute:: comment
(parental key to :class:`Comment`)
A parental key to the comment that started the thread.
.. attribute:: user
(foreign key to user model)
A foreign key to the user who added this comment.
.. attribute:: text
(text)
The text content of the comment.
.. attribute:: created_at
(date/time)
The date/time when the comment was created.
.. attribute:: updated_at
(date/time)
The date/time when the comment was updated.
2022-07-20 15:49:25 +00:00
```
2021-04-30 13:03:57 +00:00
2022-07-20 15:49:25 +00:00
## `PageSubscription`
2021-04-30 13:03:57 +00:00
Represents a user's subscription to email notifications about page events.
Currently only used for comment notifications.
2022-07-20 15:49:25 +00:00
### Database fields
2021-04-30 13:03:57 +00:00
2022-07-20 15:49:25 +00:00
```{eval-rst}
2021-04-30 13:03:57 +00:00
.. class:: PageSubscription
.. attribute:: page
(parental key to :class:`Page`)
.. attribute:: user
(foreign key to user model)
.. attribute:: comment_notifications
(boolean)
Whether the user should receive comment notifications for all comments,
or just comments in threads they participate in.
2022-07-20 15:49:25 +00:00
```