ValueError:不能将具有类型列表的对象用于空间查找参数。 Geodjango模型

时间:2019-08-01 18:34:55

标签: django geodjango spatial-query

在尝试构建Geodjango应用程序时,遇到了ValueError。我没有进行任何空间查询,但被ValueError: Cannot use object with type list for a spatial lookup parameter.困扰,我将Point对象制成了GEOS Point对象,该如何解决呢?

from __future__ import unicode_literals
from django.contrib.gis.db import models as geomodels
from django.utils.crypto import get_random_string
from django.contrib.gis.geos import GEOSGeometry,Point


# Create your models here.

geos_pnt=Point(4314498.56, 1003834.600)
#pnt=GEOSGeometry('POINT(4314498.56, 1003834.600)').wkt
class Apartment(geomodels.Model):

    apt_id = get_random_string(length=8)
    location = geomodels.PointField(default=pnt,extent=(4282586.10,996190.90,4346411.02,1011478.31),
                                    blank=True, null=True, srid=3857, help_text="Point(longitude latitude)")
    apt_cost = geomodels.FloatField(default=0.0)
    apt_area = geomodels.FloatField(default=0.0)
    SUBCITY_CHOICES = (('ADK','Addis Ketema'),('AKLTY','Akaki-Kality'),('ARD','Arada'), ('BL','Bole'), ('GL','Gulele'),
        ('KLF', 'Kolfe-Keranio'), ('LDTA','Ledeta'), ('NFS','Nefas Silk'), ('YK','Yeka'))
    apt_subcity = geomodels.CharField(default='NFS',max_length=100, choices=SUBCITY_CHOICES)
    register_date = geomodels.DateTimeField('Register Date',auto_now_add=True,null=True)


    def save(self, *args, **kwargs):
        #self.Latitude = self..y
        #self.Longitude = self.location.x
        super(Apartment, self).save(*args, **kwargs)

        class Meta:
           # order of drop-down list items

           ordering = ('apt_cost',)

            # plural form in admin view
           verbose_name_plural = 'apartments'

        def __unicode__(self):
            return self.apt_id

0 个答案:

没有答案