dkoug Blog

Geojson example

Django -- Posted on May 12, 2018

Geojson example

1
2
3
4
5
6
7
8
9
from django.contrib.gis.serializers import geojson


def get_category_poi(request):
    category = request.GET.get('category')
    poi = Poi.objects.filter(category_id=category)
    g = geojson.Serializer()
    data = g.serialize(poi, geometry_field='geom', fields=('name', 'category'))
    return HttpResponse(data, content_type='application/json')