model_reference.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. ===============
  2. Model Reference
  3. ===============
  4. .. automodule:: wagtail.wagtailcore.models
  5. This document contains reference information for the model classes inside the ``wagtailcore`` module.
  6. .. _page-model-ref:
  7. ``Page``
  8. ========
  9. Database fields
  10. ~~~~~~~~~~~~~~~
  11. .. class:: Page
  12. .. attribute:: title
  13. (text)
  14. Human-readable title of the page.
  15. .. attribute:: slug
  16. (text)
  17. This is used for constructing the page's URL.
  18. For example: ``http://domain.com/blog/[my-slug]/``
  19. .. attribute:: content_type
  20. (foreign key to ``django.contrib.contenttypes.models.ContentType``)
  21. A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this page.
  22. .. attribute:: live
  23. (boolean)
  24. A boolean that is set to ``True`` if the page is published.
  25. Note: this field defaults to ``True`` meaning that any pages that are created programmatically will be published by default.
  26. .. attribute:: has_unpublished_changes
  27. (boolean)
  28. A boolean that is set to ``True`` when the page is either in draft or published with draft changes.
  29. .. attribute:: owner
  30. (foreign key to user model)
  31. A foreign key to the user that created the page.
  32. .. attribute:: first_published_at
  33. (date/time)
  34. The date/time when the page was first published.
  35. .. attribute:: seo_title
  36. (text)
  37. Alternate SEO-crafted title, for use in the page's ``<title>`` HTML tag.
  38. .. attribute:: search_description
  39. (text)
  40. SEO-crafted description of the content, used for search indexing. This is also suitable for the page's ``<meta name="description">`` HTML tag.
  41. .. attribute:: show_in_menus
  42. (boolean)
  43. Toggles whether the page should be included in site-wide menus.
  44. This is used by the :meth:`~wagtail.wagtailcore.query.PageQuerySet.in_menu` QuerySet filter.
  45. Methods and properties
  46. ~~~~~~~~~~~~~~~~~~~~~~
  47. 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.
  48. .. class:: Page
  49. .. autoattribute:: specific
  50. .. autoattribute:: specific_class
  51. .. autoattribute:: url
  52. .. autoattribute:: full_url
  53. .. automethod:: relative_url
  54. .. automethod:: get_site
  55. .. automethod:: get_url_parts
  56. .. automethod:: route
  57. .. automethod:: serve
  58. .. automethod:: get_context
  59. .. automethod:: get_template
  60. .. automethod:: get_admin_display_title
  61. .. autoattribute:: preview_modes
  62. .. automethod:: serve_preview
  63. .. automethod:: get_parent
  64. .. automethod:: get_ancestors
  65. .. automethod:: get_descendants
  66. .. automethod:: get_siblings
  67. .. attribute:: search_fields
  68. A list of fields to be indexed by the search engine. See Search docs :ref:`wagtailsearch_indexing_fields`
  69. .. attribute:: subpage_types
  70. 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``:
  71. .. code-block:: python
  72. class BlogIndex(Page):
  73. subpage_types = ['mysite.BlogPage', 'mysite.BlogArchivePage']
  74. The creation of child pages can be blocked altogether for a given page by setting it's subpage_types attribute to an empty array:
  75. .. code-block:: python
  76. class BlogPage(Page):
  77. subpage_types = []
  78. .. attribute:: parent_page_types
  79. 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:
  80. .. code-block:: python
  81. class BlogPage(Page):
  82. parent_page_types = ['mysite.BlogIndexPage']
  83. 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):
  84. .. code-block:: python
  85. class HiddenPage(Page):
  86. parent_page_types = []
  87. .. automethod:: can_exist_under
  88. .. automethod:: can_create_at
  89. .. automethod:: can_move_to
  90. .. attribute:: password_required_template
  91. 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`
  92. .. attribute:: is_creatable
  93. 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 <https://docs.djangoproject.com/en/1.8/topics/db/models/#multi-table-inheritance>`_, to stop the base model from being created as an actual page.
  94. .. attribute:: base_form_class
  95. The form class used as a base for editing Pages of this type in the Wagtail page editor.
  96. This attribute can be set on a model to customise the Page editor form.
  97. Forms must be a subclass of :class:`~wagtail.wagtailadmin.forms.WagtailAdminPageForm`.
  98. See :ref:`custom_edit_handler_forms` for more information.
  99. .. _site-model-ref:
  100. ``Site``
  101. ========
  102. 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.
  103. 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.
  104. Database fields
  105. ~~~~~~~~~~~~~~~
  106. .. class:: Site
  107. .. attribute:: hostname
  108. (text)
  109. This is the hostname of the site, excluding the scheme, port and path.
  110. For example: ``www.mysite.com``
  111. .. note::
  112. If you're looking for how to get the root url of a site, use the :attr:`~Site.root_url` attribute.
  113. .. attribute:: port
  114. (number)
  115. This is the port number that the site responds on.
  116. .. attribute:: site_name
  117. (text - optional)
  118. 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.
  119. For example: ``Rod's World of Birds``
  120. .. attribute:: root_page
  121. (foreign key to :class:`~wagtail.wagtailcore.models.Page`)
  122. 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.
  123. .. attribute:: is_default_site
  124. (boolean)
  125. This is set to ``True`` if the site is the default. Only one site can be the default.
  126. The default site is used as a fallback in situations where a site with the required hostname/port couldn't be found.
  127. Methods and properties
  128. ~~~~~~~~~~~~~~~~~~~~~~
  129. .. class:: Site
  130. .. automethod:: find_for_request
  131. .. autoattribute:: root_url
  132. This returns the URL of the site. It is calculated from the :attr:`~Site.hostname` and the :attr:`~Site.port` fields.
  133. The scheme part of the URL is calculated based on value of the :attr:`~Site.port` field:
  134. - 80 = ``http://``
  135. - 443 = ``https://``
  136. - Everything else will use the ``http://`` scheme and the port will be appended to the end of the hostname (eg. ``http://mysite.com:8000/``)
  137. .. automethod:: get_site_root_paths
  138. .. _page-revision-model-ref:
  139. ``PageRevision``
  140. ================
  141. 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.
  142. - Revisions can be created from any :class:`~wagtail.wagtailcore.models.Page` object by calling its :meth:`~Page.save_revision` method
  143. - The content of the page is JSON-serialised and stored in the :attr:`~PageRevision.content_json` field
  144. - You can retrieve a ``PageRevision`` as a :class:`~wagtail.wagtailcore.models.Page` object by calling the :meth:`~PageRevision.as_page_object` method
  145. Database fields
  146. ~~~~~~~~~~~~~~~
  147. .. class:: PageRevision
  148. .. attribute:: page
  149. (foreign key to :class:`~wagtail.wagtailcore.models.Page`)
  150. .. attribute:: submitted_for_moderation
  151. (boolean)
  152. ``True`` if this revision is in moderation
  153. .. attribute:: created_at
  154. (date/time)
  155. This is the time the revision was created
  156. .. attribute:: user
  157. (foreign key to user model)
  158. This links to the user that created the revision
  159. .. attribute:: content_json
  160. (text)
  161. This field contains the JSON content for the page at the time the revision was created
  162. Managers
  163. ~~~~~~~~
  164. .. class:: PageRevision
  165. .. attribute:: objects
  166. This manager is used to retrieve all of the ``PageRevision`` objects in the database
  167. Example:
  168. .. code-block:: python
  169. PageRevision.objects.all()
  170. .. attribute:: submitted_revisions
  171. This manager is used to retrieve all of the ``PageRevision`` objects that are awaiting moderator approval
  172. Example:
  173. .. code-block:: python
  174. PageRevision.submitted_revisions.all()
  175. Methods and properties
  176. ~~~~~~~~~~~~~~~~~~~~~~
  177. .. class:: PageRevision
  178. .. automethod:: as_page_object
  179. This method retrieves this revision as an instance of its :class:`~wagtail.wagtailcore.models.Page` subclass.
  180. .. automethod:: approve_moderation
  181. Calling this on a revision that's in moderation will mark it as approved and publish it
  182. .. automethod:: reject_moderation
  183. Calling this on a revision that's in moderation will mark it as rejected
  184. .. automethod:: is_latest_revision
  185. Returns ``True`` if this revision is its page's latest revision
  186. .. automethod:: publish
  187. Calling this will copy the content of this revision into the live page object. If the page is in draft, it will be published.
  188. ``GroupPagePermission``
  189. =======================
  190. Database fields
  191. ~~~~~~~~~~~~~~~
  192. .. class:: GroupPagePermission
  193. .. attribute:: group
  194. (foreign key to ``django.contrib.auth.models.Group``)
  195. .. attribute:: page
  196. (foreign key to :class:`~wagtail.wagtailcore.models.Page`)
  197. .. attribute:: permission_type
  198. (choice list)
  199. ``PageViewRestriction``
  200. =======================
  201. Database fields
  202. ~~~~~~~~~~~~~~~
  203. .. class:: PageViewRestriction
  204. .. attribute:: page
  205. (foreign key to :class:`~wagtail.wagtailcore.models.Page`)
  206. .. attribute:: password
  207. (text)
  208. ``Orderable`` (abstract)
  209. ========================
  210. Database fields
  211. ~~~~~~~~~~~~~~~
  212. .. class:: Orderable
  213. .. attribute:: sort_order
  214. (number)