Skip to main content

Geojson serializer decorator for django rest framework

Project description

DRF geojson serializer is a decorator which allows to format data as geojson

Quick start

Geojson serializer works with django rest framework as a decorator.

  1. Add django-geojson_serializer to your INSTALLED_APPS setting like this:

  2. In your code you can use geojson_serializer(<name-of-geo-field>) decorator with a regualar serializer, e.g.:

    from geojson_serializer.serializers import geojson_serializer
    class City(models.Model):
        name = models.CharField(max_length=128)
        location = models.PointField()
    class CitySerializer(serializers.ModelSerializer):
        class Meta:
            model = City
            fields =['name', 'location']
    class CityViewSet(viewsets.ModelViewSet):
        queryset = City.objects.all()
        serializer_class = CitySerializer

    Then you can register CityViewSet with a router and the view will generate and accept geojsons in corresponding requests.

  3. Also supported are id and bbox fields:

    @geojson_serializer('location', id='id', bbox='bounding_box')
    class MySerializer(serializers.ModelSerializer):

    In this case 'id' and 'bounding_box' fields should be defined by the underlying serializer MySerializer.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-geojson-serializer, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size django_geojson_serializer-0.3-py2-none-any.whl (5.3 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size django-geojson_serializer-0.3.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page