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.
Add django-geojson_serializer to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ .... 'geojson_serializer' ]
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.
Also supported are
id
andbbox
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 serializerMySerializer
.
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
Built Distribution
Hashes for django-geojson_serializer-0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3795109809776919b220b392eff29281b1b007d7e6b0421351cbe5a9b4022894 |
|
MD5 | 4e0969d4204a30313d695ec08a407317 |
|
BLAKE2b-256 | 65167a390ebf00f97f89d3be1522d8b32021859750e7bc3a00eda3ffcac0498a |
Hashes for django_geojson_serializer-0.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375c6519ef8f6cdeba616121dac1783212e8600547cb6bf1415e0779225b5fe5 |
|
MD5 | 9e0d56eaf9a69a3de58c71bc9d71b2c5 |
|
BLAKE2b-256 | 29f2b1846146ababccc9191b5ec0acfa90c2826ec06b29ba52bb56cab6483bea |