【问题标题】:Create graphene-django interface from models从模型创建 graphene-django 接口
【发布时间】:2019-07-07 16:35:37
【问题描述】:

我正在使用 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】:

    graphene.Field 的参数应该是继承自 DjangoObjectType 的类,并且不是 Django 模型,例如

    class TestType(DjangoObjectType):
    
        class Meta:
            model = Test
    

    【讨论】:

      猜你喜欢
      • 2017-08-15
      • 2018-12-05
      • 2020-07-08
      • 1970-01-01
      • 2021-09-24
      • 2020-07-18
      • 2023-03-15
      • 1970-01-01
      • 2018-07-13
      相关资源
      最近更新 更多