From 682fc923613ae227c0f71b531542122fdebc252a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 28 Nov 2016 22:20:42 +0000 Subject: [PATCH] start work on stream fields --- project/common/fields.py | 12 ++++++++++++ project/projects/models.py | 10 ++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 project/common/fields.py diff --git a/project/common/fields.py b/project/common/fields.py new file mode 100644 index 0000000..7f508d1 --- /dev/null +++ b/project/common/fields.py @@ -0,0 +1,12 @@ +from wagtail.wagtailcore.fields import StreamField +from wagtail.wagtailcore import blocks + + +def build_stream_field(): + return StreamField([ + ('h1', blocks.CharBlock(classname="h1", label="H1")), + ('h2', blocks.CharBlock(classname="h2", label="H2")), + ('paragraph', blocks.RichTextBlock()), + ('raw_html', blocks.RawHTMLBlock(label="Raw HTML")), + ('list', blocks.ListBlock(blocks.CharBlock(label="List Item"))) + ]) diff --git a/project/projects/models.py b/project/projects/models.py index dc7235f..373a6b5 100644 --- a/project/projects/models.py +++ b/project/projects/models.py @@ -1,13 +1,11 @@ from django.db import models from django.core.exceptions import ValidationError - +from project.common.fields import build_stream_field from wagtail.wagtailcore.models import Page -from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel -from wagtail.wagtailadmin.edit_handlers import FieldPanel +from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index - from project.common.models import Entity @@ -32,7 +30,7 @@ class ProjectPage(Entity): related_name='+' ) summary = models.CharField(max_length=500) - body = RichTextField() + body = build_stream_field() project_url = models.URLField(validators=[validate_url], blank=True) download_url = models.URLField(validators=[validate_url], blank=True) asset = models.ForeignKey( @@ -53,7 +51,7 @@ class ProjectPage(Entity): content_panels = Page.content_panels + [ ImageChooserPanel('main_image'), FieldPanel('summary'), - FieldPanel('body'), + StreamFieldPanel('body'), FieldPanel('download_url'), FieldPanel('project_url'), DocumentChooserPanel('asset')