【发布时间】:2017-01-17 06:33:50
【问题描述】:
在主页和搜索页面,我想列出各种不同的详细显示页面。我在文档后面写了下面的代码:
from wagtail.wagtailcore.models import Page
from my.models import ArticlePage, GalleryPage, VideoPage, SharedLinkPage
PAGE_TYPES = (ArticlePage, GalleryPage, VideoPage, SharedLinkPage,)
class HomePage(Page):
subpage_types = list(PAGE_TYPES)
def get_context(self, request):
context = super(HomePage, self).get_context(request)
context['posts'] = Page.objects.type(PAGE_TYPES).live()
context['recent_posts'] = Page.objects.type(PAGE_TYPES).live()
return context
在这种情况下,我只能得到[<Page: 1>, <Page:2>],我真正想要的是[<ArticlePage: 1>, <GalleryPage:2>]。
我的问题在搜索页面中是相同的,但使用search 查询:
Page.search('something', ArticlePage)
会更好:
search_backend.search('something').types(PAGE_TYPES).live()
【问题讨论】:
标签: django django-models wagtail