【发布时间】:2014-09-16 07:16:46
【问题描述】:
我不断收到此错误:
TypeError at /
<Section: BILAY - 001> is not JSON serializable
在我看来.py:
def display_maps(request):
pnt = ButuanMaps.objects.get(clandpin='162-03-0001-017-33').geom
query_section = Section.objects.all().order_by('sbrgyid__cbrgyname')
query_soiltype = SoilType.objects.all()
query_maps = ButuanMaps.objects.filter(landproperty__sownerid__id=5, geom__distance_lte=(pnt, D(km=100)),narea__lte =5500000)
djf = Django.Django(geodjango='geom', properties= ['id','clandpin','ssectionid','narea'])
geoj = GeoJSON.GeoJSON()
butuan_agao = geoj.encode(djf.decode(query_maps.transform(3857)))
...
return render(request, "index.html", {
'butuan_agao': butuan_agao,
'query_agao': query_maps,
'query_section': query_section,
'butuan_soil': butuan_soil,
'query_soiltype': query_soiltype
})
在我的 models.py 中:
class ButuanMaps(gismodel.Model):
class Meta:
verbose_name = u'Butuan Map'
verbose_name_plural = u'Butuan Maps'
clandpin = gismodel.CharField("Land PIN", max_length=50, null=True, blank=True)
ssectionid = gismodel.ForeignKey(Section)
narea = gismodel.DecimalField(max_digits=20, decimal_places=6)
#ssectionid_id = gismodel.IntegerField()
geom = gismodel.MultiPolygonField("Geom ID", srid=32651, null=True, blank=True)
objects = gismodel.GeoManager()
def __unicode__(self):
return self.clandpin
当我在属性上添加 narea 和 ssectionid 时,它会返回错误。为什么?在这一行:
djf = Django.Django(geodjango='geom', properties= ['id','clandpin','ssectionid','narea'])
【问题讨论】:
标签: python json serialization geojson geodjango