2015-07-06 18:22:48 +00:00
===============
2015-05-29 11:53:48 +00:00
Model Reference
===============
2015-05-18 10:36:40 +00:00
2017-11-17 10:23:27 +00:00
.. automodule :: wagtail.core.models
2015-05-18 10:36:40 +00:00
2015-05-29 11:53:48 +00:00
This document contains reference information for the model classes inside the `` wagtailcore `` module.
2016-03-06 04:14:51 +00:00
.. _page-model-ref:
2015-05-29 11:53:48 +00:00
`` Page ``
2015-07-06 18:22:48 +00:00
========
2015-05-18 13:44:18 +00:00
2015-07-07 08:18:22 +00:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 10:36:40 +00:00
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)
Toggles whether the page should be included in site-wide menus.
2018-02-06 14:10:45 +00:00
This is used by the :meth: `~wagtail.core.query.PageQuerySet.in_menu` QuerySet filter.
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.
2015-05-18 10:36:40 +00:00
2016-05-10 13:28:34 +00:00
Methods and properties
~~~~~~~~~~~~~~~~~~~~~~
2015-07-07 08:18:22 +00:00
2017-01-28 00:11:52 +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.
2015-07-07 08:18:22 +00:00
2017-11-11 10:28:58 +00:00
.. note ::
See also `django-treebeard <http://django-treebeard.readthedocs.io/en/latest/index.html> `_ 's `node API <http://django-treebeard.readthedocs.io/en/latest/api.html> `_ . `` Page `` is a subclass of `materialized path tree <http://django-treebeard.readthedocs.io/en/latest/mp_tree.html> `_ nodes.
2015-07-07 08:18:22 +00:00
.. class :: Page
2015-02-19 16:53:24 +00:00
.. autoattribute :: specific
.. autoattribute :: specific_class
2018-05-18 14:26:06 +00:00
.. automethod :: get_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
.. automethod :: get_context
.. automethod :: get_template
2016-09-28 13:55:38 +00:00
.. automethod :: get_admin_display_title
2015-02-19 16:53:24 +00:00
.. autoattribute :: preview_modes
.. automethod :: serve_preview
2017-01-26 16:44:53 +00:00
.. automethod :: get_parent
2015-02-19 16:53:24 +00:00
.. automethod :: get_ancestors
.. automethod :: get_descendants
.. automethod :: get_siblings
.. 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
2015-10-10 02:17:54 +00:00
A whitelist 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
The creation of child pages can be blocked altogether for a given page by setting it's subpage_types attribute to an empty array:
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
2015-10-10 02:17:54 +00:00
A whitelist 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
2015-10-10 02:17:54 +00:00
.. automethod :: can_exist_under
.. automethod :: can_create_at
.. automethod :: can_move_to
2015-02-19 16:53:24 +00:00
.. attribute :: password_required_template
Defines which template file should be used to render the login form for Protected pages using this model. This overrides the default, defined using `` 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
2018-11-14 11:48:32 +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: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.
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.
Useful when you have relations that do not use `ClusterableModel` or should not be copied.
.. 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
The form class used as a base for editing Pages of this type in the Wagtail page editor.
This attribute can be set on a model to customise 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
2016-10-01 19:04:46 +00:00
.. _site-model-ref:
2015-05-18 10:36:40 +00:00
`` Site ``
2015-07-06 18:22:48 +00:00
========
2015-05-18 10:36:40 +00:00
2015-05-18 15:30:55 +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.
2017-11-17 10:23:27 +00:00
This configuration is used by the :class: `~wagtail.core.middleware.SiteMiddleware` middleware class which checks each request against this configuration and appends the Site object to the Django request object.
2015-05-18 15:30:55 +00:00
2015-07-07 08:18:22 +00:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 10:36:40 +00:00
2015-07-07 08:18:22 +00:00
.. class :: Site
2015-05-18 15:30:55 +00:00
.. attribute :: hostname
(text)
This is the hostname of the site, excluding the scheme, port and path.
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
2017-11-17 10:23:27 +00:00
(foreign key to :class: `~wagtail.core.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.
2015-07-07 08:18:22 +00:00
Methods and properties
~~~~~~~~~~~~~~~~~~~~~~
.. class :: Site
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:
- 80 = `` http:// ``
- 443 = `` https:// ``
- Everything else will use the `` http:// `` scheme and the port will be appended to the end of the hostname (eg. `` http://mysite.com:8000/ `` )
2015-05-18 10:36:40 +00:00
.. automethod :: get_site_root_paths
2016-03-06 04:14:51 +00:00
.. _page-revision-model-ref:
2015-05-18 10:36:40 +00:00
`` PageRevision ``
2015-07-06 18:22:48 +00:00
================
2015-05-18 10:36:40 +00:00
2015-05-29 11:53:48 +00:00
Every time a page is edited a new `` PageRevision `` 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 15:30:55 +00:00
2017-11-17 10:23:27 +00:00
- Revisions can be created from any :class: `~wagtail.core.models.Page` object by calling its :meth: `~Page.save_revision` method
2015-05-29 13:21:08 +00:00
- The content of the page is JSON-serialised and stored in the :attr: `~PageRevision.content_json` field
2017-11-17 10:23:27 +00:00
- You can retrieve a `` PageRevision `` as a :class: `~wagtail.core.models.Page` object by calling the :meth: `~PageRevision.as_page_object` method
2015-05-18 15:30:55 +00:00
2015-07-07 08:18:22 +00:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 15:30:55 +00:00
2015-07-07 08:18:22 +00:00
.. class :: PageRevision
2015-05-18 15:30:55 +00:00
.. attribute :: page
2017-11-17 10:23:27 +00:00
(foreign key to :class: `~wagtail.core.models.Page` )
2015-05-18 15:30:55 +00:00
.. attribute :: submitted_for_moderation
(boolean)
2015-05-29 11:53:48 +00:00
`` True `` if this revision is in moderation
2015-05-18 15:30:55 +00:00
.. attribute :: created_at
(date/time)
This is the time the revision was created
.. attribute :: user
(foreign key to user model)
2015-05-29 11:53:48 +00:00
This links to the user that created the revision
2015-05-18 15:30:55 +00:00
.. attribute :: content_json
(text)
This field contains the JSON content for the page at the time the revision was created
2015-07-07 08:18:22 +00:00
Managers
~~~~~~~~
.. class :: PageRevision
2015-05-18 15:30:55 +00:00
.. attribute :: objects
This manager is used to retrieve all of the `` PageRevision `` objects in the database
Example:
.. code-block :: python
PageRevision.objects.all()
.. attribute :: submitted_revisions
This manager is used to retrieve all of the `` PageRevision `` objects that are awaiting moderator approval
Example:
.. code-block :: python
PageRevision.submitted_revisions.all()
2015-07-07 08:18:22 +00:00
Methods and properties
~~~~~~~~~~~~~~~~~~~~~~
.. class :: PageRevision
2015-05-29 11:53:48 +00:00
2015-05-18 10:36:40 +00:00
.. automethod :: as_page_object
2017-11-17 10:23:27 +00:00
This method retrieves this revision as an instance of its :class: `~wagtail.core.models.Page` subclass.
2015-05-18 15:30:55 +00:00
2015-05-18 10:36:40 +00:00
.. automethod :: approve_moderation
2015-05-18 15:30:55 +00:00
Calling this on a revision that's in moderation will mark it as approved and publish it
2015-05-18 10:36:40 +00:00
.. automethod :: reject_moderation
2015-05-18 15:30:55 +00:00
Calling this on a revision that's in moderation will mark it as rejected
2015-05-18 10:36:40 +00:00
.. automethod :: is_latest_revision
2015-05-18 15:30:55 +00:00
Returns `` True `` if this revision is its page's latest revision
2015-05-18 10:36:40 +00:00
.. automethod :: publish
2015-05-18 15:30:55 +00:00
Calling this will copy the content of this revision into the live page object. If the page is in draft, it will be published.
2015-05-18 10:36:40 +00:00
`` GroupPagePermission ``
2015-07-06 18:22:48 +00:00
=======================
2015-05-18 10:36:40 +00:00
2015-07-07 08:18:22 +00:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 10:36:40 +00:00
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
2017-11-17 10:23:27 +00:00
(foreign key to :class: `~wagtail.core.models.Page` )
2015-05-18 15:30:55 +00:00
.. attribute :: permission_type
(choice list)
2015-05-18 10:36:40 +00:00
`` PageViewRestriction ``
2015-07-06 18:22:48 +00:00
=======================
2015-05-18 10:36:40 +00:00
2015-07-07 08:18:22 +00:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 10:36:40 +00:00
2015-07-07 08:18:22 +00:00
.. class :: PageViewRestriction
2015-05-18 15:30:55 +00:00
.. attribute :: page
2017-11-17 10:23:27 +00:00
(foreign key to :class: `~wagtail.core.models.Page` )
2015-05-18 15:30:55 +00:00
.. attribute :: password
(text)
2015-05-18 10:36:40 +00:00
`` Orderable `` (abstract)
2015-07-06 18:22:48 +00:00
========================
2015-05-18 10:36:40 +00:00
2015-07-07 08:18:22 +00:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 15:30:55 +00:00
2015-07-07 08:18:22 +00:00
.. class :: Orderable
2015-05-18 15:30:55 +00:00
.. attribute :: sort_order
(number)