Django-rest-framework-gis related area

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?

+3
source share
2

, DRF-gis:

Django Rest Framework -

EventLocation "" EventSerializer, .

+1

- , MultiPolygon Point. :

class AreaSerializer(gis_serializers.GeoFeatureModelSerializer):

    class Meta:
        model = Area
        geo_field = "geom"

, geo_field, ?

, :

https://github.com/kelvinn/alerted-us-web/blob/master/apps/alertdb/serializers.py

+1

Source: https://habr.com/ru/post/1680539/


All Articles