从模型创建石墨烯-django接口

问题描述 投票:0回答:1

我正在使用graphene-django,我想创建四个接口,每个接口代表Django中的模型,我将从一个模型开始:

class TestInterface(graphene.Interface):
    items = graphene.Field(models.Test)

但我一直收到这个错误:

AttributeError: type object 'Test' has no attribute 'name'

有任何想法吗?

python django graphql graphene-python
1个回答
0
投票

graphene.Field的论证应该是一个继承自DjangoObjectType而不是Django模型的类,例如:

class TestType(DjangoObjectType):

    class Meta:
        model = Test
© www.soinside.com 2019 - 2024. All rights reserved.