1
Fork 0

start work on stream fields

This commit is contained in:
Jake Howard 2016-11-28 22:20:42 +00:00
parent 4fe11dd71c
commit 682fc92361
2 changed files with 16 additions and 6 deletions

12
project/common/fields.py Normal file
View file

@ -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")))
])

View file

@ -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')