model_reference.rst 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. ===============
  2. Model Reference
  3. ===============
  4. .. automodule:: wagtail.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:: draft_title
  16. (text)
  17. 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).
  18. .. attribute:: slug
  19. (text)
  20. This is used for constructing the page's URL.
  21. For example: ``http://domain.com/blog/[my-slug]/``
  22. .. attribute:: content_type
  23. (foreign key to ``django.contrib.contenttypes.models.ContentType``)
  24. A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this page.
  25. .. attribute:: live
  26. (boolean)
  27. A boolean that is set to ``True`` if the page is published.
  28. Note: this field defaults to ``True`` meaning that any pages that are created programmatically will be published by default.
  29. .. attribute:: has_unpublished_changes
  30. (boolean)
  31. A boolean that is set to ``True`` when the page is either in draft or published with draft changes.
  32. .. attribute:: owner
  33. (foreign key to user model)
  34. A foreign key to the user that created the page.
  35. .. attribute:: first_published_at
  36. (date/time)
  37. The date/time when the page was first published.
  38. .. attribute:: last_published_at
  39. (date/time)
  40. The date/time when the page was last published.
  41. .. attribute:: seo_title
  42. (text)
  43. Alternate SEO-crafted title, for use in the page's ``<title>`` HTML tag.
  44. .. attribute:: search_description
  45. (text)
  46. SEO-crafted description of the content, used for search indexing. This is also suitable for the page's ``<meta name="description">`` HTML tag.
  47. .. attribute:: show_in_menus
  48. (boolean)
  49. Toggles whether the page should be included in site-wide menus, and is shown in the ``promote_panels`` within the Page editor.
  50. Wagtail does not include any menu implementation by default, which means that this field will not do anything in the front facing content unless built that way in a specific Wagtail installation.
  51. However, this is used by the :meth:`~wagtail.query.PageQuerySet.in_menu` QuerySet filter to make it easier to query for pages that use this field.
  52. Defaults to ``False`` and can be overridden on the model with ``show_in_menus_default = True``.
  53. .. note::
  54. To set the global default for all pages, set ``Page.show_in_menus_default = True`` once where you first import the ``Page`` model.
  55. .. attribute:: locked
  56. (boolean)
  57. When set to ``True``, the Wagtail editor will not allow any users to edit
  58. the content of the page.
  59. If ``locked_by`` is also set, only that user can edit the page.
  60. .. attribute:: locked_by
  61. (foreign key to user model)
  62. The user who has currently locked the page. Only this user can edit the page.
  63. If this is ``None`` when ``locked`` is ``True``, nobody can edit the page.
  64. .. attribute:: locked_at
  65. (date/time)
  66. The date/time when the page was locked.
  67. .. attribute:: alias_of
  68. (foreign key to another page)
  69. If set, this page is an alias of the page referenced in this field.
  70. .. attribute:: locale
  71. (foreign key to Locale)
  72. This foreign key links to the ``Locale`` object that represents the page language.
  73. .. attribute:: translation_key
  74. (uuid)
  75. A UUID that is shared between translations of a page. These are randomly generated
  76. when a new page is created and copied when a translation of a page is made.
  77. A translation_key value can only be used on one page in each locale.
  78. Methods and properties
  79. ~~~~~~~~~~~~~~~~~~~~~~
  80. 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.
  81. .. note::
  82. See also `django-treebeard <https://django-treebeard.readthedocs.io/en/latest/index.html>`_'s `node API <https://django-treebeard.readthedocs.io/en/latest/api.html>`_. ``Page`` is a subclass of `materialized path tree <https://django-treebeard.readthedocs.io/en/latest/mp_tree.html>`_ nodes.
  83. .. class:: Page
  84. :noindex:
  85. .. automethod:: get_specific
  86. .. autoattribute:: specific
  87. .. autoattribute:: specific_deferred
  88. .. autoattribute:: specific_class
  89. .. autoattribute:: cached_content_type
  90. .. autoattribute:: page_type_display_name
  91. .. automethod:: get_url
  92. .. automethod:: get_full_url
  93. .. autoattribute:: full_url
  94. .. automethod:: relative_url
  95. .. automethod:: get_site
  96. .. automethod:: get_url_parts
  97. .. automethod:: route
  98. .. automethod:: serve
  99. .. autoattribute:: context_object_name
  100. Custom name for page instance in page's ``Context``.
  101. .. automethod:: get_context
  102. .. automethod:: get_template
  103. .. automethod:: get_admin_display_title
  104. .. autoattribute:: preview_modes
  105. .. automethod:: serve_preview
  106. .. automethod:: get_parent
  107. .. automethod:: get_ancestors
  108. .. automethod:: get_descendants
  109. .. automethod:: get_siblings
  110. .. automethod:: get_translations
  111. .. automethod:: get_translation
  112. .. automethod:: get_translation_or_none
  113. .. automethod:: has_translation
  114. .. automethod:: copy_for_translation
  115. .. autoattribute:: localized
  116. .. autoattribute:: localized_draft
  117. .. attribute:: search_fields
  118. A list of fields to be indexed by the search engine. See Search docs :ref:`wagtailsearch_indexing_fields`
  119. .. attribute:: subpage_types
  120. 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``:
  121. .. code-block:: python
  122. class BlogIndex(Page):
  123. subpage_types = ['mysite.BlogPage', 'mysite.BlogArchivePage']
  124. The creation of child pages can be blocked altogether for a given page by setting its subpage_types attribute to an empty array:
  125. .. code-block:: python
  126. class BlogPage(Page):
  127. subpage_types = []
  128. .. attribute:: parent_page_types
  129. 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:
  130. .. code-block:: python
  131. class BlogPage(Page):
  132. parent_page_types = ['mysite.BlogIndexPage']
  133. 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):
  134. .. code-block:: python
  135. class HiddenPage(Page):
  136. parent_page_types = []
  137. To allow for a page to be only created under the root page (for example for ``HomePage`` models) set the ``parent_page_type`` to ``['wagtailcore.Page']``.
  138. .. code-block:: python
  139. class HomePage(Page):
  140. parent_page_types = ['wagtailcore.Page']
  141. .. automethod:: can_exist_under
  142. .. automethod:: can_create_at
  143. .. automethod:: can_move_to
  144. .. automethod:: get_route_paths
  145. .. attribute:: password_required_template
  146. 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`
  147. .. attribute:: is_creatable
  148. 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.
  149. .. attribute:: max_count
  150. 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.
  151. .. attribute:: max_count_per_parent
  152. Controls the maximum number of pages of this type that can be created under any one parent page.
  153. .. attribute:: exclude_fields_in_copy
  154. An array of field names that will not be included when a Page is copied.
  155. Useful when you have relations that do not use `ClusterableModel` or should not be copied.
  156. .. code-block:: python
  157. class BlogPage(Page):
  158. exclude_fields_in_copy = ['special_relation', 'custom_uuid']
  159. The following fields will always be excluded in a copy - `['id', 'path', 'depth', 'numchild', 'url_path', 'path']`.
  160. .. attribute:: base_form_class
  161. The form class used as a base for editing Pages of this type in the Wagtail page editor.
  162. This attribute can be set on a model to customise the Page editor form.
  163. Forms must be a subclass of :class:`~wagtail.admin.forms.WagtailAdminPageForm`.
  164. See :ref:`custom_edit_handler_forms` for more information.
  165. .. automethod:: with_content_json
  166. .. automethod:: save
  167. .. automethod:: create_alias
  168. .. automethod:: update_aliases
  169. .. autoattribute:: has_workflow
  170. .. automethod:: get_workflow
  171. .. autoattribute:: workflow_in_progress
  172. .. autoattribute:: current_workflow_state
  173. .. autoattribute:: current_workflow_task_state
  174. .. autoattribute:: current_workflow_task
  175. .. _site-model-ref:
  176. ``Site``
  177. ========
  178. 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.
  179. The :meth:`~wagtail.models.Site.find_for_request` function returns the Site object that will handle the given HTTP request.
  180. Database fields
  181. ~~~~~~~~~~~~~~~
  182. .. class:: Site
  183. .. attribute:: hostname
  184. (text)
  185. This is the hostname of the site, excluding the scheme, port and path.
  186. For example: ``www.mysite.com``
  187. .. note::
  188. If you're looking for how to get the root url of a site, use the :attr:`~Site.root_url` attribute.
  189. .. attribute:: port
  190. (number)
  191. This is the port number that the site responds on.
  192. .. attribute:: site_name
  193. (text - optional)
  194. 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.
  195. For example: ``Rod's World of Birds``
  196. .. attribute:: root_page
  197. (foreign key to :class:`~wagtail.models.Page`)
  198. 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.
  199. .. attribute:: is_default_site
  200. (boolean)
  201. This is set to ``True`` if the site is the default. Only one site can be the default.
  202. The default site is used as a fallback in situations where a site with the required hostname/port couldn't be found.
  203. Methods and properties
  204. ~~~~~~~~~~~~~~~~~~~~~~
  205. .. class:: Site
  206. :noindex:
  207. .. automethod:: find_for_request
  208. .. autoattribute:: root_url
  209. This returns the URL of the site. It is calculated from the :attr:`~Site.hostname` and the :attr:`~Site.port` fields.
  210. The scheme part of the URL is calculated based on value of the :attr:`~Site.port` field:
  211. - 80 = ``http://``
  212. - 443 = ``https://``
  213. - Everything else will use the ``http://`` scheme and the port will be appended to the end of the hostname (for example ``http://mysite.com:8000/``)
  214. .. automethod:: get_site_root_paths
  215. Locale
  216. ======
  217. The ``Locale`` model defines the set of languages and/or locales that can be used on a site.
  218. Each ``Locale`` record corresponds to a "language code" defined in the :ref:`wagtail_content_languages_setting` setting.
  219. Wagtail will initially set up one ``Locale`` to act as the default language for all existing content.
  220. 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``.
  221. If the primary language code is changed later, Wagtail will **not** automatically create a new ``Locale`` record or update an existing one.
  222. Before internationalisation is enabled, all pages use this primary ``Locale`` record.
  223. This is to satisfy the database constraints, and makes it easier to switch internationalisation on at a later date.
  224. Changing ``WAGTAIL_CONTENT_LANGUAGES``
  225. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226. Languages can be added or removed from ``WAGTAIL_CONTENT_LANGUAGES`` over time.
  227. Before removing an option from ``WAGTAIL_CONTENT_LANGUAGES``, it's important that the ``Locale``
  228. record is updated to a use a different content language or is deleted.
  229. Any ``Locale`` instances that have invalid content languages are automatically filtered out from all
  230. database queries making them unable to be edited or viewed.
  231. Methods and properties
  232. ~~~~~~~~~~~~~~~~~~~~~~
  233. .. class:: Locale
  234. :noindex:
  235. .. autoattribute:: language_code
  236. .. automethod:: get_default
  237. .. automethod:: get_active
  238. .. automethod:: get_display_name
  239. Translatable Mixin
  240. ==================
  241. ``TranslatableMixin`` is an abstract model that can be added to any non-page Django model to make it translatable.
  242. Pages already include this mixin, so there is no need to add it.
  243. Methods and properties
  244. ~~~~~~~~~~~~~~~~~~~~~~
  245. The ``locale`` and ``translation_key`` fields have a unique key constraint to prevent the object being translated into a language more than once.
  246. .. class:: TranslatableMixin
  247. :noindex:
  248. .. attribute:: locale
  249. (Foreign Key to :class:`~wagtail.models.Locale`)
  250. For pages, this defaults to the locale of the parent page.
  251. .. attribute:: translation_key
  252. (uuid)
  253. A UUID that is randomly generated whenever a new model instance is created.
  254. This is shared with all translations of that instance so can be used for querying translations.
  255. .. automethod:: get_translations
  256. .. automethod:: get_translation
  257. .. automethod:: get_translation_or_none
  258. .. automethod:: has_translation
  259. .. automethod:: copy_for_translation
  260. .. automethod:: get_translation_model
  261. .. autoattribute:: localized
  262. .. _revision_model_ref:
  263. ``Revision``
  264. ============
  265. Every time a page is edited, a new ``Revision`` 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.
  266. - Revisions can be created from any :class:`~wagtail.models.Page` object by calling its :meth:`~Page.save_revision` method
  267. - The content of the page is JSON-serialisable and stored in the :attr:`~Revision.content` field
  268. - You can retrieve a ``Revision`` as a :class:`~wagtail.models.Page` object by calling the :meth:`~Revision.as_object` method
  269. .. versionchanged:: 4.0
  270. The model has been renamed from ``PageRevision`` to ``Revision`` and it now references the ``Page`` model using a :class:`~django.contrib.contenttypes.fields.GenericForeignKey`.
  271. Database fields
  272. ~~~~~~~~~~~~~~~
  273. .. class:: Revision
  274. .. attribute:: content_object
  275. (generic foreign key)
  276. This property returns the object this revision belongs to as an instance of the specific class.
  277. .. attribute:: content_type
  278. (foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
  279. This is the content type of the object this revision belongs to. For page revisions, this means the content type of the specific page type.
  280. .. attribute:: base_content_type
  281. (foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)
  282. This is the base content type of the object this revision belongs to. For page revisions, this means the content type of the :class:`~wagtail.models.Page` model.
  283. .. attribute:: object_id
  284. (string)
  285. This represents the primary key of the object this revision belongs to.
  286. .. attribute:: submitted_for_moderation
  287. (boolean)
  288. ``True`` if this revision is in moderation
  289. .. attribute:: created_at
  290. (date/time)
  291. This is the time the revision was created
  292. .. attribute:: user
  293. (foreign key to user model)
  294. This links to the user that created the revision
  295. .. attribute:: content
  296. (dict)
  297. This field contains the JSON content for the page at the time the revision was created
  298. .. versionchanged:: 3.0
  299. The field has been renamed from ``content_json`` to ``content`` and it now uses :class:`~django.db.models.JSONField` instead of
  300. :class:`~django.db.models.TextField`.
  301. Managers
  302. ~~~~~~~~
  303. .. class:: Revision
  304. :noindex:
  305. .. attribute:: objects
  306. This default manager is used to retrieve all of the ``Revision`` objects in the database. It also provides a :meth:`~wagtail.models.RevisionsManager.for_instance` method that lets you query for revisions of a specific object.
  307. Example:
  308. .. code-block:: python
  309. Revision.objects.all()
  310. Revision.objects.for_instance(my_object)
  311. .. attribute:: page_revisions
  312. This manager extends the default manager and is used to retrieve all of the ``Revision`` objects that belong to pages.
  313. Example:
  314. .. code-block:: python
  315. Revision.page_revisions.all()
  316. .. versionadded:: 4.0
  317. This manager is added as a shorthand to retrieve page revisions.
  318. .. attribute:: submitted_revisions
  319. This manager extends the default manager and is used to retrieve all of the ``Revision`` objects that are awaiting moderator approval.
  320. Example:
  321. .. code-block:: python
  322. Revision.submitted_revisions.all()
  323. Methods and properties
  324. ~~~~~~~~~~~~~~~~~~~~~~
  325. .. class:: Revision
  326. :noindex:
  327. .. automethod:: as_object
  328. This method retrieves this revision as an instance of its object's specific class. If the revision belongs to a page, it will be an instance of the :class:`~wagtail.models.Page`'s specific subclass.
  329. .. versionchanged:: 4.0
  330. This method has been renamed from ``as_page_object()`` to ``as_object()``.
  331. .. automethod:: approve_moderation
  332. Calling this on a revision that's in moderation will mark it as approved and publish it
  333. .. automethod:: reject_moderation
  334. Calling this on a revision that's in moderation will mark it as rejected
  335. .. automethod:: is_latest_revision
  336. Returns ``True`` if this revision is the object's latest revision
  337. .. automethod:: publish
  338. Calling this will copy the content of this revision into the live object. If the object is in draft, it will be published.
  339. .. autoattribute:: base_content_object
  340. This property returns the object this revision belongs to as an instance of the base class.
  341. ``GroupPagePermission``
  342. =======================
  343. Database fields
  344. ~~~~~~~~~~~~~~~
  345. .. class:: GroupPagePermission
  346. .. attribute:: group
  347. (foreign key to ``django.contrib.auth.models.Group``)
  348. .. attribute:: page
  349. (foreign key to :class:`~wagtail.models.Page`)
  350. .. attribute:: permission_type
  351. (choice list)
  352. ``PageViewRestriction``
  353. =======================
  354. Database fields
  355. ~~~~~~~~~~~~~~~
  356. .. class:: PageViewRestriction
  357. .. attribute:: page
  358. (foreign key to :class:`~wagtail.models.Page`)
  359. .. attribute:: password
  360. (text)
  361. ``Orderable`` (abstract)
  362. ========================
  363. Database fields
  364. ~~~~~~~~~~~~~~~
  365. .. class:: Orderable
  366. .. attribute:: sort_order
  367. (number)
  368. ``Workflow``
  369. ============
  370. Workflows represent sequences of tasks which much be approved for an action to be performed on a page - typically publication.
  371. Database fields
  372. ~~~~~~~~~~~~~~~
  373. .. class:: Workflow
  374. .. attribute:: name
  375. (text)
  376. Human-readable name of the workflow.
  377. .. attribute:: active
  378. (boolean)
  379. Whether or not the workflow is active: active workflows can be added to pages, and started. Inactive workflows cannot.
  380. Methods and properties
  381. ~~~~~~~~~~~~~~~~~~~~~~
  382. .. class:: Workflow
  383. :noindex:
  384. .. automethod:: start
  385. .. autoattribute:: tasks
  386. .. automethod:: deactivate
  387. .. automethod:: all_pages
  388. ``WorkflowState``
  389. =================
  390. Workflow states represent the status of a started workflow on a page.
  391. Database fields
  392. ~~~~~~~~~~~~~~~
  393. .. class:: WorkflowState
  394. .. attribute:: page
  395. (foreign key to ``Page``)
  396. The page on which the workflow has been started
  397. .. attribute:: workflow
  398. (foreign key to ``Workflow``)
  399. The workflow whose state the ``WorkflowState`` represents
  400. .. attribute:: status
  401. (text)
  402. The current status of the workflow (options are ``WorkflowState.STATUS_CHOICES``)
  403. .. attribute:: created_at
  404. (date/time)
  405. When this instance of ``WorkflowState`` was created - when the workflow was started
  406. .. attribute:: requested_by
  407. (foreign key to user model)
  408. The user who started this workflow
  409. .. attribute:: current_task_state
  410. (foreign key to ``TaskState``)
  411. The ``TaskState`` model for the task the workflow is currently at: either completing (if in progress) or the final task state (if finished)
  412. Methods and properties
  413. ~~~~~~~~~~~~~~~~~~~~~~
  414. .. class:: WorkflowState
  415. :noindex:
  416. .. attribute:: STATUS_CHOICES
  417. A tuple of the possible options for the ``status`` field, and their verbose names. Options are ``STATUS_IN_PROGRESS``, ``STATUS_APPROVED``,
  418. ``STATUS_CANCELLED`` and ``STATUS_NEEDS_CHANGES``.
  419. .. automethod:: update
  420. .. automethod:: get_next_task
  421. .. automethod:: cancel
  422. .. automethod:: finish
  423. .. automethod:: resume
  424. .. automethod:: copy_approved_task_states_to_revision
  425. .. automethod:: all_tasks_with_status
  426. .. automethod:: revisions
  427. ``Task``
  428. ========
  429. Tasks represent stages in a workflow which must be approved for the workflow to complete successfully.
  430. Database fields
  431. ~~~~~~~~~~~~~~~
  432. .. class:: Task
  433. .. attribute:: name
  434. (text)
  435. Human-readable name of the task.
  436. .. attribute:: active
  437. (boolean)
  438. Whether or not the task is active: active workflows can be added to workflows, and started. Inactive workflows cannot, and are skipped when in
  439. an existing workflow.
  440. .. attribute:: content_type
  441. (foreign key to ``django.contrib.contenttypes.models.ContentType``)
  442. A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this task.
  443. Methods and properties
  444. ~~~~~~~~~~~~~~~~~~~~~~
  445. .. class:: Task
  446. :noindex:
  447. .. autoattribute:: workflows
  448. .. autoattribute:: active_workflows
  449. .. attribute:: task_state_class
  450. The specific task state class to generate to store state information for this task. If not specified, this will be ``TaskState``.
  451. .. automethod:: get_verbose_name
  452. .. autoattribute:: specific
  453. .. automethod:: start
  454. .. automethod:: on_action
  455. .. automethod:: user_can_access_editor
  456. .. automethod:: user_can_lock
  457. .. automethod:: user_can_unlock
  458. .. automethod:: page_locked_for_user
  459. .. automethod:: get_actions
  460. .. automethod:: get_task_states_user_can_moderate
  461. .. automethod:: deactivate
  462. .. automethod:: get_form_for_action
  463. .. automethod:: get_template_for_action
  464. .. automethod:: get_description
  465. ``TaskState``
  466. =============
  467. Task states store state information about the progress of a task on a particular page revision.
  468. Database fields
  469. ~~~~~~~~~~~~~~~
  470. .. class:: TaskState
  471. .. attribute:: workflow_state
  472. (foreign key to ``WorkflowState``)
  473. The workflow state which started this task state.
  474. .. attribute:: page_revision
  475. (foreign key to ``Revision``)
  476. The page revision this task state was created on.
  477. .. attribute:: task
  478. (foreign key to ``Task``)
  479. The task that this task state is storing state information for.
  480. .. attribute:: status
  481. (text)
  482. The completion status of the task on this revision. Options are available in ``TaskState.STATUS_CHOICES``)
  483. .. attribute:: content_type
  484. (foreign key to ``django.contrib.contenttypes.models.ContentType``)
  485. A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this task.
  486. .. attribute:: started_at
  487. (date/time)
  488. When this task state was created.
  489. .. attribute:: finished_at
  490. (date/time)
  491. When this task state was cancelled, rejected, or approved.
  492. .. attribute:: finished_by
  493. (foreign key to user model)
  494. The user who completed (cancelled, rejected, approved) the task.
  495. .. attribute:: comment
  496. (text)
  497. A text comment, typically added by a user when the task is completed.
  498. Methods and properties
  499. ~~~~~~~~~~~~~~~~~~~~~~
  500. .. class:: TaskState
  501. :noindex:
  502. .. attribute:: STATUS_CHOICES
  503. A tuple of the possible options for the ``status`` field, and their verbose names. Options are ``STATUS_IN_PROGRESS``, ``STATUS_APPROVED``,
  504. ``STATUS_CANCELLED``, ``STATUS_REJECTED`` and ``STATUS_SKIPPED``.
  505. .. attribute:: exclude_fields_in_copy
  506. A list of fields not to copy when the ``TaskState.copy()`` method is called.
  507. .. autoattribute:: specific
  508. .. automethod:: approve
  509. .. automethod:: reject
  510. .. autoattribute:: task_type_started_at
  511. .. automethod:: cancel
  512. .. automethod:: copy
  513. .. automethod:: get_comment
  514. ``WorkflowTask``
  515. ================
  516. Represents the ordering of a task in a specific workflow.
  517. Database fields
  518. ~~~~~~~~~~~~~~~
  519. .. class:: WorkflowTask
  520. .. attribute:: workflow
  521. (foreign key to ``Workflow``)
  522. .. attribute:: task
  523. (foreign key to ``Task``)
  524. .. attribute:: sort_order
  525. (number)
  526. The ordering of the task in the workflow.
  527. ``WorkflowPage``
  528. ================
  529. Represents the assignment of a workflow to a page and its descendants.
  530. Database fields
  531. ~~~~~~~~~~~~~~~
  532. .. class:: WorkflowPage
  533. .. attribute:: workflow
  534. (foreign key to ``Workflow``)
  535. .. attribute:: page
  536. (foreign key to ``Page``)
  537. ``BaseLogEntry``
  538. ================
  539. An abstract base class that represents a record of an action performed on an object.
  540. Database fields
  541. ~~~~~~~~~~~~~~~
  542. .. class:: BaseLogEntry
  543. .. attribute:: content_type
  544. (foreign key to ``django.contrib.contenttypes.models.ContentType``)
  545. A foreign key to the :class:`~django.contrib.contenttypes.models.ContentType` object that represents the specific model of this model.
  546. .. attribute:: label
  547. (text)
  548. The object title at the time of the entry creation
  549. Note: Wagtail will attempt to use ``get_admin_display_title`` or the string representation of the object passed to :meth:`~LogEntryManger.log_action`
  550. .. attribute:: user
  551. (foreign key to user model)
  552. A foreign key to the user that triggered the action.
  553. .. attribute:: revision
  554. (foreign key to :class:`Revision`)
  555. A foreign key to the current revision.
  556. .. attribute:: data
  557. (dict)
  558. The JSON representation of any additional details for each action.
  559. For example source page id and title when copying from a page. Or workflow id/name and next step id/name on a workflow transition
  560. .. versionchanged:: 3.0
  561. The field has been renamed from ``data_json`` to ``data`` and it now uses :class:`~django.db.models.JSONField` instead of
  562. :class:`~django.db.models.TextField`.
  563. .. attribute:: timestamp
  564. (date/time)
  565. The date/time when the entry was created.
  566. .. attribute:: content_changed
  567. (boolean)
  568. A boolean that can set to ``True`` when the content has changed.
  569. .. attribute:: deleted
  570. (boolean)
  571. A boolean that can set to ``True`` when the object is deleted. Used to filter entries in the Site History report.
  572. Methods and properties
  573. ~~~~~~~~~~~~~~~~~~~~~~
  574. .. class:: BaseLogEntry
  575. :noindex:
  576. .. autoattribute:: user_display_name
  577. .. autoattribute:: comment
  578. .. autoattribute:: object_verbose_name
  579. .. automethod:: object_id
  580. ``PageLogEntry``
  581. ================
  582. Represents a record of an action performed on an :class:`Page`, subclasses :class:`BaseLogEntry`.
  583. Database fields
  584. ~~~~~~~~~~~~~~~
  585. .. class:: PageLogEntry
  586. .. attribute:: page
  587. (foreign key to :class:`Page`)
  588. A foreign key to the page the action is performed on.
  589. ``Comment``
  590. ===========
  591. Represents a comment on a page.
  592. Database fields
  593. ~~~~~~~~~~~~~~~
  594. .. class:: Comment
  595. .. attribute:: page
  596. (parental key to :class:`Page`)
  597. A parental key to the page the comment has been added to.
  598. .. attribute:: user
  599. (foreign key to user model)
  600. A foreign key to the user who added this comment.
  601. .. attribute:: text
  602. (text)
  603. The text content of the comment.
  604. .. attribute:: contentpath
  605. (text)
  606. The path to the field or streamfield block the comment is attached to,
  607. in the form ``field`` or ``field.streamfield_block_id``.
  608. .. attribute:: position
  609. (text)
  610. An identifier for the position of the comment within its field. The format
  611. used is determined by the field.
  612. .. attribute:: created_at
  613. (date/time)
  614. The date/time when the comment was created.
  615. .. attribute:: updated_at
  616. (date/time)
  617. The date/time when the comment was updated.
  618. .. attribute:: revision_created
  619. (foreign key to :class:`Revision`)
  620. A foreign key to the revision on which the comment was created.
  621. .. attribute:: resolved_at
  622. (date/time)
  623. The date/time when the comment was resolved, if any.
  624. .. attribute:: resolved_by
  625. (foreign key to user model)
  626. A foreign key to the user who resolved this comment, if any.
  627. ``CommentReply``
  628. ================
  629. Represents a reply to a comment thread.
  630. Database fields
  631. ~~~~~~~~~~~~~~~
  632. .. class:: CommentReply
  633. .. attribute:: comment
  634. (parental key to :class:`Comment`)
  635. A parental key to the comment that started the thread.
  636. .. attribute:: user
  637. (foreign key to user model)
  638. A foreign key to the user who added this comment.
  639. .. attribute:: text
  640. (text)
  641. The text content of the comment.
  642. .. attribute:: created_at
  643. (date/time)
  644. The date/time when the comment was created.
  645. .. attribute:: updated_at
  646. (date/time)
  647. The date/time when the comment was updated.
  648. ``PageSubscription``
  649. ====================
  650. Represents a user's subscription to email notifications about page events.
  651. Currently only used for comment notifications.
  652. Database fields
  653. ~~~~~~~~~~~~~~~
  654. .. class:: PageSubscription
  655. .. attribute:: page
  656. (parental key to :class:`Page`)
  657. .. attribute:: user
  658. (foreign key to user model)
  659. .. attribute:: comment_notifications
  660. (boolean)
  661. Whether the user should receive comment notifications for all comments,
  662. or just comments in threads they participate in.