diff options
author | Jonathan DeMasi <jonathan.demasi@colorado.edu> | 2020-03-06 00:06:59 -0700 |
---|---|---|
committer | Jonathan DeMasi <jonathan.demasi@colorado.edu> | 2020-03-06 00:06:59 -0700 |
commit | 235342bf086c91c27b8f3e607112e7ae0065835b (patch) | |
tree | 5d1dc9c4c5ee8a6f7852a607997d4addad886d21 | |
parent | 34d1793c321a86123aa30f40d5d4cd4192968f4a (diff) | |
download | jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.tar jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.tar.gz jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.tar.bz2 jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.tar.lz jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.tar.xz jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.tar.zst jthanio-235342bf086c91c27b8f3e607112e7ae0065835b.zip |
streamfield for blog posts!
-rw-r--r-- | blog/migrations/0008_auto_20200306_0703.py | 23 | ||||
-rw-r--r-- | blog/models.py | 23 | ||||
-rw-r--r-- | blog/templates/blog/blog_post.html | 2 | ||||
-rw-r--r-- | home/migrations/0004_auto_20200306_0656.py | 23 | ||||
-rw-r--r-- | home/models.py | 23 | ||||
-rw-r--r-- | home/templates/home/home_page.html | 2 |
6 files changed, 85 insertions, 11 deletions
diff --git a/blog/migrations/0008_auto_20200306_0703.py b/blog/migrations/0008_auto_20200306_0703.py new file mode 100644 index 0000000..c19bb80 --- /dev/null +++ b/blog/migrations/0008_auto_20200306_0703.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.3 on 2020-03-06 07:03 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.embeds.blocks +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0007_blogpostgalleryimage'), + ] + + operations = [ + migrations.AlterField( + model_name='blogpost', + name='body', + field=wagtail.core.fields.StreamField([('heading', wagtail.core.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('page', wagtail.core.blocks.PageChooserBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock()), ('media', wagtail.embeds.blocks.EmbedBlock()), ('html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML'))]), + ), + ] diff --git a/blog/models.py b/blog/models.py index 9b92ce8..ab9f381 100644 --- a/blog/models.py +++ b/blog/models.py @@ -1,10 +1,14 @@ from django.db import models from django import forms from wagtail.core.models import Page, Orderable -from wagtail.core.fields import RichTextField -from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel +from wagtail.core.fields import RichTextField, StreamField +from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel, StreamFieldPanel from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.search import index +from wagtail.documents.blocks import DocumentChooserBlock +from wagtail.embeds.blocks import EmbedBlock +from wagtail.images.blocks import ImageChooserBlock +from wagtail.core import blocks from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.contrib.taggit import ClusterTaggableManager @@ -38,7 +42,16 @@ class BlogPostTag(TaggedItemBase): class BlogPost(Page): date = models.DateField("Post date") intro = models.CharField(max_length=250) - body = RichTextField(blank=True) + body = StreamField( + [ + ('heading', blocks.CharBlock(classname="full title")), + ('paragraph', blocks.RichTextBlock()), + ('image', ImageChooserBlock()), + ('page', blocks.PageChooserBlock()), + ('document', DocumentChooserBlock()), + ('media', EmbedBlock()), + ('html', blocks.RawHTMLBlock(label='Raw HTML')), + ]) tags = ClusterTaggableManager(through=BlogPostTag, blank=True) categories = ParentalManyToManyField('blog.BlogCategory', blank=True) @@ -62,7 +75,7 @@ class BlogPost(Page): ], heading="Blog information"), InlinePanel('gallery_images', label="Gallery images"), FieldPanel('intro'), - FieldPanel('body', classname="full") + StreamFieldPanel('body'), ] class BlogTagIndexPage(Page): @@ -102,4 +115,4 @@ class BlogPostGalleryImage(Orderable): panels = [ ImageChooserPanel('image'), FieldPanel('caption'), - ]
\ No newline at end of file + ] diff --git a/blog/templates/blog/blog_post.html b/blog/templates/blog/blog_post.html index 7a0a291..8d4ac63 100644 --- a/blog/templates/blog/blog_post.html +++ b/blog/templates/blog/blog_post.html @@ -30,7 +30,7 @@ <!-- Post Content --> <p class="lead">{{ page.intro }}</p> - {{ page.body|richtext }} + {% include_block page.body %} </div> diff --git a/home/migrations/0004_auto_20200306_0656.py b/home/migrations/0004_auto_20200306_0656.py new file mode 100644 index 0000000..604f118 --- /dev/null +++ b/home/migrations/0004_auto_20200306_0656.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.3 on 2020-03-06 06:56 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.embeds.blocks +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0003_homepage_body'), + ] + + operations = [ + migrations.AlterField( + model_name='homepage', + name='body', + field=wagtail.core.fields.StreamField([('heading', wagtail.core.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('page', wagtail.core.blocks.PageChooserBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock()), ('media', wagtail.embeds.blocks.EmbedBlock()), ('html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML'))]), + ), + ] diff --git a/home/models.py b/home/models.py index dc320e5..d5a2cba 100644 --- a/home/models.py +++ b/home/models.py @@ -1,13 +1,28 @@ from django.db import models from wagtail.core.models import Page +from wagtail.core.fields import StreamField +from wagtail.core import blocks from wagtail.core.fields import RichTextField -from wagtail.admin.edit_handlers import FieldPanel +from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel +from wagtail.documents.blocks import DocumentChooserBlock +from wagtail.embeds.blocks import EmbedBlock +from wagtail.images.blocks import ImageChooserBlock class HomePage(Page): - body = RichTextField(blank=True) + body = StreamField( + [ + ('heading', blocks.CharBlock(classname="full title")), + ('paragraph', blocks.RichTextBlock()), + ('image', ImageChooserBlock()), + ('page', blocks.PageChooserBlock()), + ('document', DocumentChooserBlock()), + ('media', EmbedBlock()), + ('html', blocks.RawHTMLBlock(label='Raw HTML')), + ]) + content_panels = Page.content_panels + [ - FieldPanel('body', classname="full"), - ]
\ No newline at end of file + StreamFieldPanel('body'), + ] diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index 3509151..d7cc373 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -17,7 +17,7 @@ <hr> - {{ page.body|richtext }} + {% include_block page.body %} </div> |