类别模型 这是我的类别模型
class Category(models.Model):
_id = models.ObjectIdField(primary_key=True)
name = models.CharField(max_length=100)
类别节点 我使用中继创建了一个类别节点
class CategoryNode(DjangoObjectType):
class Meta:
model = Category
filter_fields = ['name', 'equipments']
interfaces = (relay.Node,)
在突变时添加设备突变 我需要在突变输入中将类别对象添加到设备对象
class AddEquipment(relay.ClientIDMutation):
class Input:
name = graphene.String(required=True)
category = graphene.Field(CategoryNode)
equipment = graphene.Field(EquipmentNode)
@classmethod
def mutate_and_get_payload(cls, root, info, **inputs):
equipment_instance = Equipment(
name=inputs.get('name'),
category=inputs.get('category')
)
equipment_instance.save()
return AddEquipment(equipment=equipment_instance)
通过这段代码,我得到了这样的错误
“AssertionError:AddEquipmentInput.category 字段类型必须是 Input Type 但得到:CategoryNode。”