不知道如何转换Django字段(<class'django.contrib.gis.db.models.fields.MultiLineStringField'>)

时间:2019-11-28 01:09:04

标签: django django-models graphql gis geodjango

我正在尝试对我的graphql api进行查询,当我使用邮递员对我的api查询时,出现下一个错误。
我知道该错误表明它不知道如何在我的路由模型中转换MultiLineStringField字段 route = models.MultiLineStringField(),我认为我应该手动执行此操作,但我不知道在哪里或如何。
graphql api是使用Django 2.2.7,graphene 2.1.8构建的。

这是错误:

Exception at /graphql
Don't know how to convert the Django field routes.Route.route (<class 'django.contrib.gis.db.models.fields.MultiLineStringField'>)
Request Method: POST
Request URL:    http://localhost:8000/graphql
Django Version: 2.2.7
Exception Type: Exception
Exception Value:    
Don't know how to convert the Django field routes.Route.route (<class 'django.contrib.gis.db.models.fields.MultiLineStringField'>)
Exception Location: /home/jccari/code/gosip-server/venv/lib/python3.6/site-packages/graphene_django/converter.py in convert_django_field, line 95
Python Executable:  /home/jccari/code/gosip-server/venv/bin/python
Python Version: 3.6.8
Python Path:    
['/home/jccari/code/gosip-server',
 '/home/jccari/code/gosip-server/venv/lib/python36.zip',
 '/home/jccari/code/gosip-server/venv/lib/python3.6',
 '/home/jccari/code/gosip-server/venv/lib/python3.6/lib-dynload',
 '/usr/lib/python3.6',
 '/home/jccari/code/gosip-server/venv/lib/python3.6/site-packages']
Server time:    Thu, 28 Nov 2019 00:30:29 +0000

路线模型:

from django.contrib.gis.db import models

class Route(models.Model):
    name = models.CharField(max_length=50)
    route = models.MultiLineStringField()

    def __str__(self):
        return self.name

这是我的querys.py

import graphene
from graphene_django.types import DjangoObjectType, ObjectType
from ..models import Route

class RouteType(DjangoObjectType):
    class Meta:
        model = Route

class Query(ObjectType):
    route = graphene.Field(RouteType, id=graphene.Int())
    routes = graphene.List(RouteType)

    def resolve_route(self, info, **kwargs):
        id = kwargs.get('id')
        if id is not None:
            return Route.objects.get(pk=id)
        return None

    def resolve_routes(self, info, **kwargs):
        return Route.objects.all()

我尝试使用this解决问题,但是我没有任何运气。 感谢您的帮助。预先感谢。

0 个答案:

没有答案