问题描述
我是 wagtail 的新手并试图理解它。我遇到了一个问题,需要一些帮助。
我已经设置了石墨烯和graphql。我也能够获取所有数据,但我需要获取父页面数据和子页面数据。我尝试了多种选择,但没有任何效果。
所以页面结构如下:WorkIndexPage > FullStackPage > TechnologyPage。
这是我的models.py
from __future__ import unicode_literals
from django.db import models
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.admin.edit_handlers import (FieldPanel,StreamFieldPanel,MultiFieldPanel,InlinePanel)
from modelcluster.fields import ParentalKey
# Create your models here.
from wagtail.core.models import Page,Orderable
from wagtail.core.fields import RichTextField,StreamField
from wagtail.core import blocks as work_blocks
from wagtail.search import index
class WorkIndexPage(Page):
pass
class FullStackPage(Page):
description = RichTextField(blank=True)
def child_pages(self):
return TechnologyPage.objects.all().child_of(self)
content_panels = Page.content_panels + [
FieldPanel('description',classname="full"),]
subpage_types = ['work.TechnologyPage']
class TechnologyDetailOrderable(Orderable):
page = ParentalKey("work.TechnologyPage",related_name="technologypage")
software_title = models.CharField(max_length=255)
description = RichTextField(blank=True)
class TechnologyPage(Page):
content_panels = Page.content_panels + [
MultiFieldPanel([
InlinePanel('technologypage',label="Technology Details"),],heading="Technology or Framework details"),]
这是我的 schema.py
from __future__ import unicode_literals
import graphene
from graphene_django import DjangoObjectType
from about.models import AboutPage
from work.models import FullStackPage,TechnologyPage
from django.db import models
from api import graphene_wagtail
class AboutNode(DjangoObjectType):
class Meta:
model = AboutPage
only_fields = ['id','title','content','side_image']
class FullStackWorkNode(DjangoObjectType):
class Meta:
model = FullStackPage
only_fields = ['id','description']
class TechnologyWorkNode(DjangoObjectType):
class Meta:
model = TechnologyPage
only_fields = ['id','title']
class Query(graphene.ObjectType):
about = graphene.List(AboutNode)
full_stack = graphene.List(FullStackWorkNode)
def resolve_about(self,arg):
return AboutPage.objects.all()
def resolve_full_stack(self,arg):
return FullStackPage.objects.all()
schema = graphene.Schema(query=Query)
我得到的输出如图所示
但我也希望将 TechnologyPage 字段作为我的 FullStackPage json 中的子页面。
任何帮助将不胜感激。提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)