我正在使用Django 1.8,使用GeoDjango和PostGIS。我正在使用HttpResponse
返回一些GeoJSON:
from django.http import HttpResponse, JsonResponse
code = request.GET.get('q', '')
results = PCT.objects.filter(Q(code__startswith=code) |
Q(name__icontains=code))
results = results.filter(org_type='CCG')
for result in results:
print result.code
geo_field = 'boundary'
fields = ('name', 'code', 'ons_code', 'org_type', 'boundary', )
return HttpResponse(serialize('geojson', results,
geometry_field=geo_field, fields=fields),
content_type='application/json')
在控制台中,这个代码可以很好地打印出一个
code
字段:99N
但是返回的GeoJSON没有
properties.code
字段,它有properties.name
、properties.org_type
和properties.ons_code
字段。为什么会这样呢?code
可能是一个保留名称吗?如果是,我该如何解决?