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 http://geojson.org

Quick start

Geojson serializer works with django rest framework as a decorator.

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

    INSTALLED_APPS = [
    ....
    'geojson_serializer'
    ]
  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()
    
    
    @geojson_serializer('location')
    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.

Source Distribution

django-geojson_serializer-0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

django_geojson_serializer-0.3-py2-none-any.whl (5.3 kB view details)

Uploaded Python 2

File details

Details for the file django-geojson_serializer-0.3.tar.gz.

File metadata

  • Download URL: django-geojson_serializer-0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.5

File hashes

Hashes for django-geojson_serializer-0.3.tar.gz
Algorithm Hash digest
SHA256 3795109809776919b220b392eff29281b1b007d7e6b0421351cbe5a9b4022894
MD5 4e0969d4204a30313d695ec08a407317
BLAKE2b-256 65167a390ebf00f97f89d3be1522d8b32021859750e7bc3a00eda3ffcac0498a

See more details on using hashes here.

File details

Details for the file django_geojson_serializer-0.3-py2-none-any.whl.

File metadata

  • Download URL: django_geojson_serializer-0.3-py2-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.5

File hashes

Hashes for django_geojson_serializer-0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 375c6519ef8f6cdeba616121dac1783212e8600547cb6bf1415e0779225b5fe5
MD5 9e0d56eaf9a69a3de58c71bc9d71b2c5
BLAKE2b-256 29f2b1846146ababccc9191b5ec0acfa90c2826ec06b29ba52bb56cab6483bea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page