【发布时间】:2019-08-27 00:05:58
【问题描述】:
我有一个 graphene-python DjangoObjectType 类,我想添加一个自定义类型,但是我不知道如何在解析器函数中获取当前模型实例。我正在关注this tutorial,但找不到任何参考。
这是我的 DjangoObjectTypeClass:
class ReservationComponentType(DjangoObjectType):
component_str = graphene.String()
class Meta:
model = ReservationComponent
def resolve_component_str(self, info):
# How can I get the current ReservationComponent instance here?. I guess it is somewehere in 'info',
# but documentation says nothing about it
current_reservation_component = info.get('reservation_component')
component = current_reservation_component.get_component()
return component.name
我的问题与Graphene resolver for an object that has no model 不同,因为我的对象确实有模型。我不知道为什么它被标记为“可能重复”,并且有如此明显的差异。我的问题确实是基于模型。
【问题讨论】:
-
@PetarP 不,这不是一个重复的问题,因为我的对象确实有一个模型,而且我的问题确实基于这样的模型。您引用的问题与我要解决的问题有关
-
操作,抱歉,没有正确阅读,将删除它。
-
嘿,这里,docs中有很好的例子
标签: python django graphene-python