I have a geographic model structure where several events can have the same location:
class Event(models.Model):
name = models.CharField(max_length=128, blank=True, null=True)
location = models.ForeignKey('MarketLocation', null=True, blank=True)
class EventLocation(models.Model):
location = models.PointField(srid=4326)
I use the GeoFeatureModelSerializerprovided django-rest-framework-gis to output a single JSON object, but it PointFielddisplays as a string instead of a pair of coordinates:
So this gives me:
"location": "POINT (-1.909 53.7094)"
Instead:
"point": {
"type": "Point",
"coordinates": [-123.0208, 44.0464],
},
The logical answer would be to define a field in the serializer:
geo_field = eventlocation__location
But this makes no difference to the conclusion, which makes me think that it probably is not working, but it is likely to happen. Has anyone done this job, and if so, how?
source
share