Reputation: 169
When I run a QuerySet on a class model in Wagtail I get the error.
NameError: name 'BlogPage' is not defined
Here is the code:
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")
]
However, if I run a QuerySet using the Parent Page class I get the expected result.
Page.objects.all()
[<Page: Root>, <Page: Homepage>, <Page: Blog Page Index>, <Page: Post number 1>, <Page: Post number 2>, <Page: Post number 3>]
What will be to correct way of defining the BlogPage and other page classes that inherit from the Page class?
Upvotes: 2
Views: 1367
Reputation: 14311
At the command line, after you:
import wagtail
...you also need to import your BlogPage model like so:
from myapp.models import BlogPage
Good luck!
Upvotes: 2