python - Django's GeoJSON serializer not serializing all fields? -


i'm using django 1.8, geodjango , postgis. using httpresponse return 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') 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') 

in console prints code field fine:

99n 

but geojson returned not have properties.code field. has properties.name, properties.org_type , properties.ons_code field though.

enter image description here

why this? code reserved name perhaps? if so, how can fix this?

i've had quick @ geojson spec , appear goes far properties field json object in own right, think you're in letter of current specification if want in part of json dump. said, spec still in draft form , subject change (and may yet place constraints on field). assuming can live that, can continue...

the code handles in geojson serializer. create data geometry, type , properties fields in get_dump_object(). you'll note properties field renders whatever in self._current. field built (by parent classes' methods) serializer iterates on rest of fields in object.

by time get_dump_object() called, self._current should contain other serializable fields in object. can see in base serializer class, fields serialized if constructed serialize=true , field in list of specified fields passed in serialize() (or didn't specify filter you're going everything). therefore guess code field has been declared not serializable, or has unexpected internal name doesn't match filter.

to try fix it, have @ declaration of code field in model bad serialize parameter, try serializing without field list @ all. 1 of gets missing field json.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -