错误模型名称未在Wagtail CMS中定义

时间:2016-01-04 03:01:11

标签: wagtail

当我在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和其他页面类的方法?

1 个答案:

答案 0 :(得分:2)

在命令行中,在您之后:

import wagtail

...你还需要导入你的BlogPage模型:

from myapp.models import BlogPage
祝你好运!