Django Rest Framework Gis, trying to get a GEOjson output

865 views Asked by At

Hello I am trying to generate a GEOJSON output with Djano Rest Framework Gis :

Here is my Models.py

from django.contrib.gis.db import models
from django_autoslug.fields import AutoSlugField
from django_extensions.db.fields import UUIDField

class Location(models.Model):
    name = models.CharField(max_length=255)
    slug = AutoSlugField(populate_from='name', max_length=255)
    uuid = UUIDField(auto=True)
    point = models.PointField(help_text="Represented as (longitude, latitude)")
    objects = models.GeoManager()

and the serializers.py

from django.forms import widgets
from rest_framework_gis import serializers
from locateMe.models import Location

class LocationSerializer(serializers.GeoFeatureModelSerializer):
    class Meta:
        model = Location
        geo_field = "point"
        id_field = "slug"
        fields = ('slug', 'uuid')

And I obtain this error :

  argument of type 'NoneType' is not iterable
  Exception Location: ../rest_framework_gis/serializers.py in from_native, line 115

So I had a look at /rest_framework_gis/serializers.py

def from_native(self, data, files):
    """
    Override the parent method to first remove the GeoJSON formatting
    """
    if 'features' in data:
        _unformatted_data = []
        features = data['features']
        for feature in features:
            _dict = feature["properties"]
            geom = { self.opts.geo_field: feature["geometry"] }
            _dict.update(geom)
            _unformatted_data.append(_dict)
    elif 'properties' in data:
        _dict = data["properties"]
        geom = { self.opts.geo_field: data["geometry"] }
        _dict.update(geom)
        _unformatted_data = _dict
    else:
        _unformatted_data = data

    data = _unformatted_data

    instance = super(GeoFeatureModelSerializer, self).from_native(data, files)
    if not self._errors:
        return self.full_clean(instance)

It might be obvious but I can't see what is wrong

0

There are 0 answers