I'm really new to Python3, Django & Wagtail and am trying to create an ArticlePage Model with a StreamField block used in it, and have run into problems and am getting an error:
AttributeError: 'CharField' object has no attribute 'stream_block' error.
I have no idea what I'm doing wrong?
I'm obviously doing something wrong but have no idea what?
Here's the model.py code:
articles/models.py:
from modelcluster.fields import ParentalKey
from wagtail.core import blocks
from wagtail.core.models import Page, Orderable
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, MultiFieldPanel, InlinePanel
from wagtail.core.fields import StreamField
from streams import blocks
from wagtail.core.fields import RichTextField
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index
### Flexible Page
# Create your models here.
class ArticlePage(Page):
subtitle = models.CharField()
body = RichTextField()
date = models.DateField("Article date")
team_member = models.CharField()
feed_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
search_fields = Page.search_fields + [
index.SearchField('body'),
index.FilterField('date'),
index.FilterField('subtitle'),
]
template = "articles/article_page.html"
#ToDo: add StreamFields
content = StreamField(
[
("team_member", blocks.TeamMembersBlock())
],
null=True,
blank=True,
)
subtitle = models.CharField()
content_panels = Page.content_panels + [
FieldPanel("subtitle"),
FieldPanel('date'),
FieldPanel('body', classname="full"),
InlinePanel('related_links', label="Related links"),
StreamFieldPanel("team_member"),
]
promote_panels = [
MultiFieldPanel(Page.promote_panels, "Common page configuration"),
ImageChooserPanel('feed_image'),
]
# Parent page / subpage type rules
parent_page_types = ['articles.ArticleIndex']
subpage_types = []
class Meta: # noqa
verbose_name = "Flex Page"
verbose_name_plural = "Flex Pages"
# Create your models here.
class ArticlePageRelatedLink(Orderable):
page = ParentalKey(ArticlePage, on_delete=models.CASCADE,
related_name='related_links')
name = models.CharField()
url = models.URLField()
panels = [
FieldPanel('name'),
FieldPanel('url'),
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…