2015-07-06 20:22:48 +02:00
===============
2015-05-29 13:53:48 +02:00
Model Reference
===============
2015-05-18 12:36:40 +02:00
2015-05-29 13:53:48 +02:00
.. automodule :: wagtail.wagtailcore.models
2015-05-18 12:36:40 +02:00
2015-05-29 13:53:48 +02:00
This document contains reference information for the model classes inside the `` wagtailcore `` module.
`` Page ``
2015-07-06 20:22:48 +02:00
========
2015-05-18 15:44:18 +02:00
2015-07-07 10:18:22 +02:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
.. class :: Page
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: title
(text)
2015-05-18 12:36:40 +02:00
2015-05-18 15:44:18 +02:00
Human-readable title of the page.
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: slug
(text)
2015-05-29 13:53:48 +02:00
This is used for constructing the page's URL.
2015-05-18 17:30:55 +02:00
For example: `` http://domain.com/blog/[my-slug]/ ``
.. attribute :: content_type
(foreign key to `` django.contrib.contenttypes.models.ContentType `` )
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
A foreign key to the :class: `~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this page.
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: live
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
(boolean)
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
A boolean that is set to `` True `` if the page is published.
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
Note: this field defaults to `` True `` meaning that any pages that are created programmatically will be published by default.
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: has_unpublished_changes
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
(boolean)
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
A boolean that is set to `` True `` when the page is either in draft or published with draft changes.
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: owner
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
(foreign key to user model)
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
A foreign key to the user that created the page.
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: first_published_at
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
(date/time)
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02:00
The date/time when the page was first published.
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: seo_title
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02:00
(text)
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02:00
Alternate SEO-crafted title, for use in the page's `` <title> `` HTML tag.
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02:00
.. attribute :: search_description
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02:00
(text)
2015-05-18 15:44:18 +02:00
2015-05-18 17:30:55 +02: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.
This is used by the :meth: `~wagtail.wagtailcore.query.PageQuerySet.in_menu` QuerySet filter.
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
Methods and properies
~~~~~~~~~~~~~~~~~~~~~
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. Those listed here are relatively straightforward to use, but consult the Wagtail source code for a full view of what's possible.
.. class :: Page
2015-02-19 17:53:24 +01:00
.. autoattribute :: specific
.. autoattribute :: specific_class
.. autoattribute :: url
.. autoattribute :: full_url
.. automethod :: route
.. automethod :: serve
.. automethod :: get_context
.. automethod :: get_template
.. autoattribute :: preview_modes
.. automethod :: serve_preview
.. automethod :: get_ancestors
.. automethod :: get_descendants
.. automethod :: get_siblings
.. attribute :: search_fields
A list of fields to be indexed by the search engine. See Search docs :ref: `wagtailsearch_indexing_fields`
.. attribute :: subpage_types
A whitelist of page models which can be created as children of this page type e.g a `` BlogIndex `` page might allow `` BlogPage `` , but not `` JobPage `` e.g
.. code-block :: python
class BlogIndex(Page):
subpage_types = ['mysite.BlogPage', 'mysite.BlogArchivePage']
2015-02-21 11:05:41 +01: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 e.g
.. code-block :: python
class BlogPage(Page):
subpage_types = []
.. attribute :: parent_page_types
A whitelist of page models which are allowed as parent page types e.g a `` BlogPage `` may only allow itself to be created below the `` BlogIndex `` page e.g
.. code-block :: python
class BlogPage(Page):
parent_page_types = ['mysite.BlogIndexPage']
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) e.g
.. code-block :: python
class HiddenPage(Page):
parent_page_types = []
2015-02-19 17:53:24 +01: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 12:36:40 +02:00
`` Site ``
2015-07-06 20:22:48 +02:00
========
2015-05-18 12:36:40 +02:00
2015-05-18 17:30:55 +02: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.
This configuration is used by the :class: `~wagtail.wagtailcore.middleware.SiteMiddleware` middleware class which checks each request against this configuration and appends the Site object to the Django request object.
2015-07-07 10:18:22 +02:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
.. class :: Site
2015-05-18 17:30:55 +02: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.
.. attribute :: root_page
(foreign key to :class: `~wagtail.wagtailcore.models.Page` )
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 10:18:22 +02:00
Methods and properties
~~~~~~~~~~~~~~~~~~~~~~
.. class :: Site
2015-05-18 17:30:55 +02:00
2015-05-18 12:36:40 +02:00
.. automethod :: find_for_request
.. autoattribute :: root_url
2015-05-18 17:30:55 +02: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 12:36:40 +02:00
.. automethod :: get_site_root_paths
`` PageRevision ``
2015-07-06 20:22:48 +02:00
================
2015-05-18 12:36:40 +02:00
2015-05-29 13:53:48 +02: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 17:30:55 +02:00
2015-08-05 15:13:00 +02:00
- Revisions can be created from any :class: `~wagtail.wagtailcore.models.Page` object by calling its :meth: `~Page.save_revision` method
2015-05-29 15:21:08 +02:00
- The content of the page is JSON-serialised and stored in the :attr: `~PageRevision.content_json` field
2015-05-29 13:53:48 +02:00
- You can retrieve a `` PageRevision `` as a :class: `~wagtail.wagtailcore.models.Page` object by calling the :meth: `~PageRevision.as_page_object` method
2015-05-18 17:30:55 +02:00
2015-07-07 10:18:22 +02:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 17:30:55 +02:00
2015-07-07 10:18:22 +02:00
.. class :: PageRevision
2015-05-18 17:30:55 +02:00
.. attribute :: page
(foreign key to :class: `~wagtail.wagtailcore.models.Page` )
.. attribute :: submitted_for_moderation
(boolean)
2015-05-29 13:53:48 +02:00
`` True `` if this revision is in moderation
2015-05-18 17:30:55 +02:00
.. attribute :: created_at
(date/time)
This is the time the revision was created
.. attribute :: user
(foreign key to user model)
2015-05-29 13:53:48 +02:00
This links to the user that created the revision
2015-05-18 17:30:55 +02:00
.. attribute :: content_json
(text)
This field contains the JSON content for the page at the time the revision was created
2015-07-07 10:18:22 +02:00
Managers
~~~~~~~~
.. class :: PageRevision
2015-05-18 17:30:55 +02: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 10:18:22 +02:00
Methods and properties
~~~~~~~~~~~~~~~~~~~~~~
.. class :: PageRevision
2015-05-29 13:53:48 +02:00
2015-05-18 12:36:40 +02:00
.. automethod :: as_page_object
2015-05-18 17:30:55 +02:00
This method retrieves this revision as an instance of its :class: `~wagtail.wagtailcore.models.Page` subclass.
2015-05-18 12:36:40 +02:00
.. automethod :: approve_moderation
2015-05-18 17:30:55 +02:00
Calling this on a revision that's in moderation will mark it as approved and publish it
2015-05-18 12:36:40 +02:00
.. automethod :: reject_moderation
2015-05-18 17:30:55 +02:00
Calling this on a revision that's in moderation will mark it as rejected
2015-05-18 12:36:40 +02:00
.. automethod :: is_latest_revision
2015-05-18 17:30:55 +02:00
Returns `` True `` if this revision is its page's latest revision
2015-05-18 12:36:40 +02:00
.. automethod :: publish
2015-05-18 17:30:55 +02: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 12:36:40 +02:00
`` GroupPagePermission ``
2015-07-06 20:22:48 +02:00
=======================
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
.. class :: GroupPagePermission
2015-05-18 17:30:55 +02:00
.. attribute :: group
(foreign key to `` django.contrib.auth.models.Group `` )
.. attribute :: page
(foreign key to :class: `~wagtail.wagtailcore.models.Page` )
.. attribute :: permission_type
(choice list)
2015-05-18 12:36:40 +02:00
`` PageViewRestriction ``
2015-07-06 20:22:48 +02:00
=======================
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
.. class :: PageViewRestriction
2015-05-18 17:30:55 +02:00
.. attribute :: page
(foreign key to :class: `~wagtail.wagtailcore.models.Page` )
.. attribute :: password
(text)
2015-05-18 12:36:40 +02:00
`` Orderable `` (abstract)
2015-07-06 20:22:48 +02:00
========================
2015-05-18 12:36:40 +02:00
2015-07-07 10:18:22 +02:00
Database fields
~~~~~~~~~~~~~~~
2015-05-18 17:30:55 +02:00
2015-07-07 10:18:22 +02:00
.. class :: Orderable
2015-05-18 17:30:55 +02:00
.. attribute :: sort_order
(number)