Wagtail のクラス モデルで QuerySet を実行すると、エラーが発生します。
NameError: name 'BlogPage' is not defined
コードは次のとおりです。
from django.db import models
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailsearch import index
class IndexPage(Page):
intro = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('intro', classname='full'),
]
class BlogPage(Page):
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
search_fields = Page.search_fields + (
index.SearchField('intro'),
index.SearchField('body'),
)
content_panels = Page.content_panels + [
FieldPanel('date'),
FieldPanel('intro'),
FieldPanel('body', classname="full")
]
ただし、Parent Page クラスを使用して QuerySet を実行すると、期待どおりの結果が得られます。
Page.objects.all()
[<Page: Root>, <Page: Homepage>, <Page: Blog Page Index>, <Page: Post number 1>, <Page: Post number 2>, <Page: Post number 3>]
Page クラスから継承する BlogPage およびその他のページ クラスを定義する正しい方法は何ですか?