Model Reference

This document contains reference information for the model classes inside the wagtailcore module.

Page

class wagtail.wagtailcore.models.Page(id, path, depth, numchild, title, slug, content_type_id, live, has_unpublished_changes, url_path, owner_id, seo_title, show_in_menus, search_description, go_live_at, expire_at, expired, locked, first_published_at, latest_revision_created_at)

Database fields:

title

(text)

Human-readable title of the page.

slug

(text)

This is used for constructing the page’s URL.

For example: http://domain.com/blog/[my-slug]/

content_type

(foreign key to django.contrib.contenttypes.models.ContentType)

A foreign key to the ContentType object that represents the specific model of this page.

live

(boolean)

A boolean that is set to True if the page is published.

Note: this field defaults to True meaning that any pages that are created programmatically will be published by default.

has_unpublished_changes

(boolean)

A boolean that is set to True when the page is either in draft or published with draft changes.

owner

(foreign key to user model)

A foreign key to the user that created the page.

first_published_at

(date/time)

The date/time when the page was first published.

seo_title

(text)

Alternate SEO-crafted title, for use in the page’s <title> HTML tag.

search_description

(text)

SEO-crafted description of the content, used for search indexing. This is also suitable for the page’s <meta name="description"> HTML tag.

show_in_menus

(boolean)

Toggles whether the page should be included in site-wide menus.

This is used by the in_menu() QuerySet filter.

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.

specific

Decorator that converts a method with a single self argument into a property cached on the instance.

specific_class

Decorator that converts a method with a single self argument into a property cached on the instance.

url

Return the ‘most appropriate’ URL for referring to this page from the pages we serve, within the Wagtail backend and actual website templates; this is the local URL (starting with ‘/’) if we’re only running a single site (i.e. we know that whatever the current page is being served from, this link will be on the same domain), and the full URL (with domain) if not. Return None if the page is not routable.

full_url

Return the full URL (including protocol / domain) to this page, or None if it is not routable

route(request, path_components)
serve(request, *args, **kwargs)
get_context(request, *args, **kwargs)
get_template(request, *args, **kwargs)
preview_modes

A list of (internal_name, display_name) tuples for the modes in which this page can be displayed for preview/moderation purposes. Ordinarily a page will only have one display mode, but subclasses of Page can override this - for example, a page containing a form might have a default view of the form, and a post-submission ‘thankyou’ page

serve_preview(request, mode_name)

Return an HTTP response for use in page previews. Normally this would be equivalent to self.serve(request), since we obviously want the preview to be indicative of how it looks on the live site. However, there are a couple of cases where this is not appropriate, and custom behaviour is required:

1) The page has custom routing logic that derives some additional required args/kwargs to be passed to serve(). The routing mechanism is bypassed when previewing, so there’s no way to know what args we should pass. In such a case, the page model needs to implement its own version of serve_preview.

2) The page has several different renderings that we would like to be able to see when previewing - for example, a form page might have one rendering that displays the form, and another rendering to display a landing page when the form is posted. This can be done by setting a custom preview_modes list on the page model - Wagtail will allow the user to specify one of those modes when previewing, and pass the chosen mode_name to serve_preview so that the page model can decide how to render it appropriately. (Page models that do not specify their own preview_modes list will always receive an empty string as mode_name.)

Any templates rendered during this process should use the ‘request’ object passed here - this ensures that request.user and other properties are set appropriately for the wagtail user bar to be displayed. This request will always be a GET.

get_ancestors(inclusive=False)
get_descendants(inclusive=False)
get_siblings(inclusive=True)
search_fields

A list of fields to be indexed by the search engine. See Search docs Indexing extra fields

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

class BlogIndex(Page):
    subpage_types = ['mysite.BlogPage', 'mysite.BlogArchivePage']

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

class BlogPage(Page):
    subpage_types = []
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

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

class HiddenPage(Page):
    parent_page_types = []
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 Private pages

Site

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 SiteMiddleware middleware class which checks each request against this configuration and appends the Site object to the Django request object.

class wagtail.wagtailcore.models.Site(id, hostname, port, root_page_id, is_default_site)

Database fields:

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 root_url attribute.

port

(number)

This is the port number that the site responds on.

root_page

(foreign key to 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.

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.

Methods and attributes:

static find_for_request(request)

Find the site object responsible for responding to this HTTP request object. Try:

  • unique hostname first
  • then hostname and port
  • if there is no matching hostname at all, or no matching hostname:port combination, fall back to the unique default site, or raise an exception

NB this means that high-numbered ports on an extant hostname may still be routed to a different hostname which is set as the default

root_url

This returns the URL of the site. It is calculated from the hostname and the port fields.

The scheme part of the URL is calculated based on value of the 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/)
static get_site_root_paths()

Return a list of (root_path, root_url) tuples, most specific path first - used to translate url_paths into actual URLs with hostnames

PageRevision

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.

  • Revisions can be created from any Page object calling its create_revision() method
  • The content of the page is JSON-serialised and stored in the content_json field
  • You can retrieve a PageRevision as a Page object by calling the as_page_object() method
class wagtail.wagtailcore.models.PageRevision(id, page_id, submitted_for_moderation, created_at, user_id, content_json, approved_go_live_at)

Database fields:

page

(foreign key to Page)

submitted_for_moderation

(boolean)

True if this revision is in moderation

created_at

(date/time)

This is the time the revision was created

user

(foreign key to user model)

This links to the user that created the revision

content_json

(text)

This field contains the JSON content for the page at the time the revision was created

Managers:

objects

This manager is used to retrieve all of the PageRevision objects in the database

Example:

PageRevision.objects.all()
submitted_revisions

This manager is used to retrieve all of the PageRevision objects that are awaiting moderator approval

Example:

PageRevision.submitted_revisions.all()

Methods and attributes:

as_page_object()

This method retrieves this revision as an instance of its Page subclass.

approve_moderation()

Calling this on a revision that’s in moderation will mark it as approved and publish it

reject_moderation()

Calling this on a revision that’s in moderation will mark it as rejected

is_latest_revision()

Returns True if this revision is its page’s latest revision

publish()

Calling this will copy the content of this revision into the live page object. If the page is in draft, it will be published.

GroupPagePermission

class wagtail.wagtailcore.models.GroupPagePermission(id, group_id, page_id, permission_type)

Database fields:

group

(foreign key to django.contrib.auth.models.Group)

page

(foreign key to Page)

permission_type

(choice list)

PageViewRestriction

class wagtail.wagtailcore.models.PageViewRestriction(id, page_id, password)

Database fields:

page

(foreign key to Page)

password

(text)

Orderable (abstract)

class wagtail.wagtailcore.models.Orderable(*args, **kwargs)

Database fields:

sort_order

(number)