Getting started

setting up a brand new Wagtail project

1
2
3
4
5
6
7
$ pip install wagtail
$ wagtail start mysite
$ cd mysite
$ pip install -r requirements.txt
$ ./manage.py migrate
$ ./manage.py createsuperuser
$ ./manage.py runserver

http://localhost:8000

http://localhost:8000/admin/

Extend the HomePage model

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# home/models.py
from django.db import models

from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel


class HomePage(Page):
    body = RichTextField(blank=True)
    
    # content_panels define the capabilities and the layout of the editing interface
    content_panels = Page.content_panels + [
        FieldPanel('body', classname="full"),
    ]
1
2
$ python manage.py makemigrations
$ python manage.py migrate

create a new app

1
$ python manage.py startapp blog

Add the new blog app to INSTALLED_APPS in mysite/settings/base.py.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# blog/models.py
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel


class BlogIndexPage(Page):
    intro = RichTextField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('intro', classname="full")
    ]

In the Wagtail admin, create a BlogIndexPage as a child of the Homepage, make sure it has the slug “blog” on the Promote tab, and publish it. You should now be able to access the url /blog on your site (note how the slug from the Promote tab defines the page URL).

Freeform page content using StreamField

Page models

Friendly model names

1
2
3
4
5
class HomePage(Page):
    ...

    class Meta:
        verbose_name = "homepage"

When users are given a choice of pages to create, the list of page types is generated by splitting your model names or verbose_name.

move up / move down child pages

  • ParentalKey
  • InlinePanel(‘form_fields’, label=‘Form_fields’)
  • refer to Contact Us page FormPage and form_fields

Model Field

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    country = models.CharField(verbose_name='country', max_length=255)
    featured_section_1 = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='First featured section for the homepage. Will display up to '
        'three child items.',
        verbose_name='Featured section 1'
    )
  • verbose_name
  • help_text

noticebody

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class NoticeBlock(StructBlock):
    """
    """
    title = CharBlock(required=False)
    summary = RichTextBlock(required=False) 
           = BooleanBlock(required=True, ) 
           
    
    notice_body = StreamField([

    ])
    

ADD

  • ParentalKey

  • InlinePanel

  • refer to blog_person_relationship

reference

Wagtail field

  • RichTextField

Django core fields

Elasticsearch.

Feature Detection.