Blog body is a stream field
This commit is contained in:
parent
dbd449b708
commit
f96124b744
9 changed files with 54 additions and 5 deletions
5
blog/blocks.py
Normal file
5
blog/blocks.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from wagtail.blocks import RichTextBlock
|
||||
|
||||
from base.blocks import StreamBlock
|
||||
class BlogPostBlock(StreamBlock):
|
||||
paragraph = RichTextBlock(blank=True)
|
20
blog/migrations/0008_alter_blogpage_body.py
Normal file
20
blog/migrations/0008_alter_blogpage_body.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 5.0.2 on 2024-03-14 02:46
|
||||
|
||||
import wagtail.blocks
|
||||
import wagtail.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0007_blogtagindexpage'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='blogpage',
|
||||
name='body',
|
||||
field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(blank=True))], blank=True, help_text='Write anything'),
|
||||
),
|
||||
]
|
|
@ -5,12 +5,15 @@ from modelcluster.contrib.taggit import ClusterTaggableManager
|
|||
from taggit.models import TaggedItemBase
|
||||
|
||||
from wagtail.models import Page, Orderable
|
||||
from wagtail.fields import RichTextField
|
||||
from wagtail.fields import RichTextField, StreamField
|
||||
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
|
||||
from wagtail.search import index
|
||||
|
||||
from wagtail.snippets.models import register_snippet
|
||||
|
||||
from blog.blocks import BlogPostBlock
|
||||
|
||||
|
||||
class BlogIndexPage(Page):
|
||||
intro = RichTextField(blank=True)
|
||||
|
||||
|
@ -46,7 +49,12 @@ class BlogPageTag(TaggedItemBase):
|
|||
class BlogPage(Page):
|
||||
date = models.DateField("Post date")
|
||||
intro = models.CharField(max_length=250)
|
||||
body = RichTextField(blank=True)
|
||||
body = StreamField(
|
||||
BlogPostBlock(),
|
||||
blank=True,
|
||||
use_json_field=True,
|
||||
help_text="Write anything",
|
||||
)
|
||||
|
||||
authors = ParentalManyToManyField('blog.Author', blank=True)
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
{% endwith %}
|
||||
|
||||
<p>{{ post.intro }}</p>
|
||||
{{ post.body|richtext }}
|
||||
{{ post.body }}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
<div class="intro">{{ page.intro }}</div>
|
||||
|
||||
{{ page.body|richtext }}
|
||||
{{ page.body }}
|
||||
|
||||
{% for item in page.gallery_images.all %}
|
||||
<div style="float: inline-start; margin: 10px">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue