Skip to content

Latest commit

 

History

History
1029 lines (549 loc) · 25.8 KB

model_reference.rst

File metadata and controls

1029 lines (549 loc) · 25.8 KB

Model Reference

wagtail.core.models

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

Page

Database fields

title

(text)

Human-readable title of the page.

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).

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 ~django.contrib.contenttypes.models.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.

last_published_at

(date/time)

The date/time when the page was last 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 ~wagtail.core.query.PageQuerySet.in_menu QuerySet filter.

Defaults to False and can be overridden on the model with show_in_menus_default = True.

Note

To set the global default for all pages, set Page.show_in_menus_default = True once where you first import the Page model.

locked

(boolean)

When set to True, the Wagtail editor will not allow any users to edit the content of the page.

If locked_by is also set, only that user can edit the page.

locked_by

(foreign key to user model)

The user who has currently locked the page. Only this user can edit the page.

If this is None when locked is True, nobody can edit the page.

locked_at

(date/time)

The date/time when the page was locked.

alias_of

(foreign key to another page)

If set, this page is an alias of the page referenced in this field.

locale

(foreign key to Locale)

This foreign key links to the Locale object that represents the page language.

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.

A translation_key value can only be used on one page in each locale.

Methods and properties

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.

Note

See also django-treebeard's node API. Page is a subclass of materialized path tree nodes.

specific

specific_class

cached_content_type

get_url

full_url

relative_url

get_site

get_url_parts

route

serve

context_object_name

Custom name for page instance in page's Context.

get_context

get_template

get_admin_display_title

preview_modes

serve_preview

get_parent

get_ancestors

get_descendants

get_siblings

get_translations

get_translation

get_translation_or_none

has_translation

copy_for_translation

localized

localized_draft

search_fields

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

subpage_types

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:

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

The creation of child pages can be blocked altogether for a given page by setting its subpage_types attribute to an empty array:

class BlogPage(Page):
    subpage_types = []

parent_page_types

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:

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):

class HiddenPage(Page):
    parent_page_types = []

can_exist_under

can_create_at

can_move_to

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

is_creatable

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 multi-table inheritance <django:multi-table-inheritance>, to stop the base model from being created as an actual page.

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.

max_count_per_parent

Controls the maximum number of pages of this type that can be created under any one parent page.

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.

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'].

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. Forms must be a subclass of ~wagtail.admin.forms.WagtailAdminPageForm. See custom_edit_handler_forms for more information.

with_content_json

save

create_alias

update_aliases

has_workflow

get_workflow

workflow_in_progress

current_workflow_state

current_workflow_task_state

current_workflow_task

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.

The ~wagtail.core.models.Site.find_for_request function returns the Site object that will handle the given HTTP request.

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

port

(number)

This is the port number that the site responds on.

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

root_page

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

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 properties

find_for_request

root_url

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

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

get_site_root_paths

Locale

The Locale model defines the set of languages and/or locales that can be used on a site. Each Locale record corresponds to a "language code" defined in the wagtail_content_languages_setting setting.

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.

Before internationalisation is enabled, all pages use this primary Locale record. This is to satisfy the database constraints, and makes it easier to switch internationalisation on at a later date.

Changing WAGTAIL_CONTENT_LANGUAGES

Languages can be added or removed from WAGTAIL_CONTENT_LANGUAGES over time.

Before removing an option from WAGTAIL_CONTENT_LANGUAGES, it's important that the Locale record is updated to a use a different content language or is deleted. Any Locale instances that have invalid content languages are automatically filtered out from all database queries making them unable to be edited or viewed.

Methods and properties

language_code

get_default

get_active

get_display_name

Translatable Mixin

TranslatableMixin is an abstract model that can be added to any non-page Django model to make it translatable. Pages already include this mixin, so there is no need to add it.

Methods and properties

The locale and translation_key fields have a unique key constraint to prevent the object being translated into a language more than once.

locale

(Foreign Key to ~wagtail.core.models.Locale)

For pages, this defaults to the locale of the parent page.

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.

get_translations

get_translation

get_translation_or_none

has_translation

copy_for_translation

get_translation_model

localized

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 ~wagtail.core.models.Page object by calling its ~Page.save_revision method
  • The content of the page is JSON-serialised and stored in the ~PageRevision.content_json field
  • You can retrieve a PageRevision as a ~wagtail.core.models.Page object by calling the ~PageRevision.as_page_object method

Database fields

page

(foreign key to ~wagtail.core.models.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 properties

as_page_object

This method retrieves this revision as an instance of its ~wagtail.core.models.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

Database fields

group

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

page

(foreign key to ~wagtail.core.models.Page)

permission_type

(choice list)

PageViewRestriction

Database fields

page

(foreign key to ~wagtail.core.models.Page)

password

(text)

Orderable (abstract)

Database fields

sort_order

(number)

Workflow

Workflows represent sequences of tasks which much be approved for an action to be performed on a page - typically publication.

Database fields

name

(text)

Human-readable name of the workflow.

active

(boolean)

Whether or not the workflow is active: active workflows can be added to pages, and started. Inactive workflows cannot.

Methods and properties

start

tasks

deactivate

all_pages

WorkflowState

Workflow states represent the status of a started workflow on a page.

Database fields

page

(foreign key to Page)

The page on which the workflow has been started

workflow

(foreign key to Workflow)

The workflow whose state the WorkflowState represents

status

(text)

The current status of the workflow (options are WorkflowState.STATUS_CHOICES)

created_at

(date/time)

When this instance of WorkflowState was created - when the workflow was started

requested_by

(foreign key to user model)

The user who started this workflow

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)

Methods and properties

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 and STATUS_NEEDS_CHANGES.

update

get_next_task

cancel

finish

resume

copy_approved_task_states_to_revision

all_tasks_with_status

revisions

Task

Tasks represent stages in a workflow which must be approved for the workflow to complete successfully.

Database fields

name

(text)

Human-readable name of the task.

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.

content_type

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

A foreign key to the ~django.contrib.contenttypes.models.ContentType object that represents the specific model of this task.

Methods and properties

workflows

active_workflows

task_state_class

The specific task state class to generate to store state information for this task. If not specified, this will be TaskState.

get_verbose_name

specific

start

on_action

user_can_access_editor

user_can_lock

user_can_unlock

page_locked_for_user

get_actions

get_task_states_user_can_moderate

deactivate

get_form_for_action

get_template_for_action

get_description

TaskState

Task states store state information about the progress of a task on a particular page revision.

Database fields

workflow_state

(foreign key to WorkflowState)

The workflow state which started this task state.

page revision

(foreign key to PageRevision)

The page revision this task state was created on.

task

(foreign key to Task)

The task that this task state is storing state information for.

status

(text)

The completion status of the task on this revision. Options are available in TaskState.STATUS_CHOICES)

content_type

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

A foreign key to the ~django.contrib.contenttypes.models.ContentType object that represents the specific model of this task.

started_at

(date/time)

When this task state was created.

finished_at

(date/time)

When this task state was cancelled, rejected, or approved.

finished_by

(foreign key to user model)

The user who completed (cancelled, rejected, approved) the task.

comment

(text)

A text comment, typically added by a user when the task is completed.

Methods and properties

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.

exclude_fields_in_copy

A list of fields not to copy when the TaskState.copy() method is called.

specific

approve

reject

task_type_started_at

cancel

copy

get_comment

WorkflowTask

Represents the ordering of a task in a specific workflow.

Database fields

workflow

(foreign key to Workflow)

task

(foreign key to Task)

sort_order

(number)

The ordering of the task in the workflow.

WorkflowPage

Represents the assignment of a workflow to a page and its descendants.

Database fields

workflow

(foreign key to Workflow)

page

(foreign key to Page)

BaseLogEntry

An abstract base class that represents a record of an action performed on an object.

Database fields

content_type

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

A foreign key to the ~django.contrib.contenttypes.models.ContentType object that represents the specific model of this model.

label

(text)

The object title at the time of the entry creation

Note: Wagtail will attempt to use get_admin_display_title or the string representation of the object passed to ~LogEntryManger.log_action

user

(foreign key to user model)

A foreign key to the user that triggered the action.

data_json

(text)

The JSON representation of any additional details for each action. e.g. source page id and title when copying from a page. Or workflow id/name and next step id/name on a workflow transition

timestamp

(date/time)

The date/time when the entry was created.

content_changed

(boolean)

A boolean that can set to True when the content has changed.

deleted

(boolean)

A boolean that can set to True when the object is deleted. Used to filter entries in the Site History report.

Methods and properties

user_display_name

data

comment

object_verbose_name

object_id

PageLogEntry

Represents a record of an action performed on an Page, subclasses BaseLogEntry.

Database fields

page

(foreign key to Page)

A foreign key to the page the action is performed on.

revision

(foreign key to PageRevision)

A foreign key to the current page revision.