1
Fork 0

Add common page model with stream field

This commit is contained in:
Jake Howard 2018-07-25 09:03:00 +01:00
parent 29a05febdb
commit bac41e2b74
Signed by: jake
GPG key ID: 57AFB45680EDD477
6 changed files with 92 additions and 0 deletions

15
project/common/blocks.py Normal file
View file

@ -0,0 +1,15 @@
from wagtail.core.fields import StreamField
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtailmarkdown.blocks import MarkdownBlock
def build_stream_field():
return StreamField([
('document', DocumentChooserBlock()),
('image', ImageChooserBlock()),
('markdown', MarkdownBlock()),
('paragraph', blocks.RichTextBlock()),
('raw_html', blocks.RawHTMLBlock(label="Raw HTML")),
])

View file

View file

@ -0,0 +1,54 @@
# Generated by Django 2.0.7 on 2018-07-25 08:02
from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.documents.blocks
import wagtail.images.blocks
import wagtailmarkdown.blocks
import wagtailmetadata.models
class Migration(migrations.Migration):
initial = True
dependencies = [
('wagtailimages', '0020_add-verbose-name'),
('wagtailcore', '0040_page_draft_title'),
]
operations = [
migrations.CreateModel(
name='SectionIndexPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('post_date', models.DateTimeField(blank=True, null=True)),
('body', wagtail.core.fields.StreamField([('document', wagtail.documents.blocks.DocumentChooserBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('markdown', wagtailmarkdown.blocks.MarkdownBlock()), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('raw_html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML'))])),
('hide_list', models.BooleanField(default=False)),
('search_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
],
options={
'abstract': False,
},
bases=(wagtailmetadata.models.MetadataMixin, 'wagtailcore.page', models.Model),
),
migrations.CreateModel(
name='SimpleContentPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('post_date', models.DateTimeField(blank=True, null=True)),
('body', wagtail.core.fields.StreamField([('document', wagtail.documents.blocks.DocumentChooserBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('markdown', wagtailmarkdown.blocks.MarkdownBlock()), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('raw_html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML'))])),
('search_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
],
options={
'abstract': False,
},
bases=(wagtailmetadata.models.MetadataMixin, 'wagtailcore.page', models.Model),
),
]

View file

22
project/pages/models.py Normal file
View file

@ -0,0 +1,22 @@
from django.db import models
from project.common.blocks import build_stream_field
from project.common.models import Entity
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
class SimpleContentPage(Entity):
body = build_stream_field()
content_panels = Entity.content_panels + [
StreamFieldPanel('body')
]
class SectionIndexPage(Entity):
body = build_stream_field()
hide_list = models.BooleanField(default=False)
content_panels = Entity.content_panels + [
StreamFieldPanel('body'),
FieldPanel('hide_list')
]

View file

@ -44,6 +44,7 @@ INSTALLED_APPS = [
'project.home',
'project.search',
'project.common',
'project.pages',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',