我只想返回clandpin
字段。我有这个模型如下:
在模型.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)
#ssectionid_id = gismodel.IntegerField()
geom = gismodel.MultiPolygonField("Geom ID", srid=32651, null=True, blank=True)
objects = gismodel.GeoManager()
def __unicode__(self):
return self.clandpin
在我的模板中,以下是AJAX的代码:
^{pr2}$在视图.py公司名称:
def section_landpins(request):
if request.method == "GET":
m = ButuanMaps.objects.filter(ssectionid=request.GET['sectionid'])
landpins = serializers.serialize("json", m.values('clandpin'), fields=("clandpin"))
data = json.dumps({
'pins': landpins,
})
return HttpResponse(data, content_type='application/json')
它返回了一个错误
AttributeError at /sectionpins'dict' object has no attribute '_meta'
当我用以下命令更改查询时:
m = ButuanMaps.objects.filter(ssectionid=request.GET['sectionid'])
它不会返回错误,但是:
{"pins": "[{\"pk\": 185625, \"model\": \"tbl.butuanmaps\", \"fields\": {\"clandpin\": \"162-12-0001-055-37\"}}
您可以通过从ORM中只请求您感兴趣的字段来完成此操作,然后将ValueQuerySet计算到字典列表中:
相关问题 更多 >
编程相关推荐