【发布时间】:2023-04-09 08:08:01
【问题描述】:
我有一些想要出现在 graphql 查询中的 django 模型通用关系字段。石墨烯是否支持泛型类型?
class Attachment(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
file = models.FileField(upload_to=user_directory_path)
class Aparto(models.Model):
agency = models.CharField(max_length=100, default='Default')
features = models.TextField()
attachments = GenericRelation(Attachment)
石墨烯类:
class ApartoType(DjangoObjectType):
class Meta:
model = Aparto
class Query(graphene.ObjectType):
all = graphene.List(ApartoType)
def resolve_all(self, info, **kwargs):
return Aparto.objects.all()
schema = graphene.Schema(query=Query)
我希望附件字段出现在 graphql 查询结果中。仅显示代理机构和功能。
【问题讨论】:
-
你应该包括你正在使用的石墨烯类。
标签: python django graphql graphene-python