GeoDjango:无法使用PointField()保存模型,错误:值类型为< class'users.models.Point'>的SpatialProxy(POINT); [英] GeoDjango: Can't save a model with PointField(), Error: SpatialProxy (POINT) with value of type: <class 'users.models.Point'>

查看:59
本文介绍了GeoDjango:无法使用PointField()保存模型,错误:值类型为< class'users.models.Point'>的SpatialProxy(POINT);的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想法是集成Google Maps而不是GeoDjango v1.11.5 PointField()的默认地图.

The idea is to integrate Google Maps instead of the default map for GeoDjango v1.11.5 PointField().

当前,在我的 models.py

class Teacher(models.Model):
    user = models.OneToOneField(User, on_delete=models.PROTECT, related_name='Teacher')
    placename = models.CharField(blank=True,max_length=255)
    latitude = models.FloatField(blank=True, null=True, verbose_name='Latitude')
    longitude = models.FloatField(blank=True, null=True, verbose_name='Longitude')
    location = models.PointField(blank = True, null=True, srid=4326)
    objects = models.GeoManager()

    def save(self, *args, **kwargs):
        self.location = Point(self.longitude, self.latitude)
        super(Teacher, self).save(*args, **kwargs)  # Call the "real" save() method.

但是,当我在手动添加long和lat之后单击保存"时,我得到:

However, when I click save after I manually add the long and lat, I get:

在/admin/users/location/add/处的

TypeError无法设置位置值类型为

TypeError at /admin/users/location/add/ Cannot set Location SpatialProxy (POINT) with value of type:

推荐答案

我认为您使用的是错误的 Point 类.如果将 Point PointField一起使用,则应该从 django.contrib.gis.geos 导入,而不是 users.models.Point .

I believe you are using the wrong Point class. Point should be imported from django.contrib.gis.geos not users.models.Point if you are using it with a PointField

您的进口商品应如下:

from django.contrib.gis.db import models
from django.contrib.gis.geos import Point

这篇关于GeoDjango:无法使用PointField()保存模型,错误:值类型为< class'users.models.Point'>的SpatialProxy(POINT);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆