Python wagtail page models














































Python wagtail page models



             Page models

Each page type  in Wagtail is represented by a Django model. All page models must inherit from the wagtail.core.models.Page class.

As all page types are Django models, you can use any field type that Django provides. . Wagtail also provides RichTextField which provides a WYSIWYG editor for editing rich-text content.

  

         An example Wagtail page model

    This example represents a typical blog post:

from django.db import models

from modelcluster.fields import ParentalKey

from wagtail.core.models import Page, Orderable
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index


class BlogPage(Page):

# Database fields

body = RichTextField()
date = models.DateField("Post date")
feed_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)


# Search index configuration

search_fields = Page.search_fields + [
index.SearchField('body'),
index.FilterField('date'),
]


# Editor panels configuration

content_panels = Page.content_panels + [
FieldPanel('date'),
FieldPanel('body', classname="full"),
InlinePanel('related_links', label="Related links"),
]

promote_panels = [
MultiFieldPanel(Page.promote_panels, "Common page configuration"),
ImageChooserPanel('feed_image'),
]


# Parent page / subpage type rules

parent_page_types = ['blog.BlogIndex']
subpage_types = []


class BlogPageRelatedLink(Orderable):
page = ParentalKey(BlogPage, on_delete=models.CASCADE, related_name='related_links')
name = models.CharField(max_length=255)
url = models.URLField()

panels = [
FieldPanel('name'),
FieldPanel('url'),
]

       

                   Different type of Database fields in classwagtail.core.models.Page

   1) title   

            Human-readable title of the page.

2)  slug
  This is used for constructing the page%u2019s URL.

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

 3) content_type

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

4)  live

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

5)  first_published_at

The date/time when the page was first published.

6)last_published_at

The date/time when the page was last published

7)  locked

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.

8) locked_by

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.

9) locked_at

The date/time when the page was locked.


More Articles of SAYENDEEP MAHANTY:

Name Views Likes
C++ Exception Handling-|| 72 3
C++ Exception Handling 102 3
C++ File Handling EOF 81 5
C++ File Handling Error Handling During file Operation 935 5
C++ File Handling seekp() Function 90 5
C++ File Handling seekg() Function 78 6
C++ File Handling tellg() Function 107 5
C++ File Handling tellp() Function 96 5
C++ File Handling close() Function 69 5
C++ File Handling:: open() 92 5
C++ File Handling Introduction 121 5
C++ Container Library:: std ::array-II 92 4
Top Django Interview Questions and Answers You Need to Know 264 6
C++ Container Library::std::array 85 6
C++ Container Library Introduction 94 5
Essential Engineering Skills for Your Resume 115 5
Mistakes To Avoid During Technical Interview 122 5
Mistakes You Must Avoid During Work From Home 164 6
Seven Common Mistakes that Beginners Should Avoid While Learning to Code 94 6
Simple Linear Regression 89 6
Python wagtailmenus 108 6
Python wagtail application 109 6
Python guppy GSL 119 5
Python wagtail guppy subpackage heapy 163 6
Python guppy Introduction 204 6
Python wagtail Structural Block 242 6
Python wagtail Integrating into Django Project 335 6
Python wagtail testing 265 7
Python wagtail Basic Block 315 7
Python wagtail image tag 209 7
Python wagtail Templates 167 6
Python wagtail Backends 187 6
Python wagtail Indexing 172 6
Python wagtail Search 166 7
Python wagtail Snippets 179 6
Python wagtail Writing your own page models 156 9
Python wagtail model class PageRevision 182 10
Python wagtail model class Site 191 9
Python wagtail wagtail core model 210 9
Python wagtail page models 180 10
Python wagtail 154 11

Comments