当我在 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>]
定义 BlogPage 和其他从 Page 类继承的页面类的正确方法是什么?