Search code examples
djangogeojsondumpdata

Django: How to include pk when to export Geojson using dumpdata?


I am using Django 'dumpdata' to export database table to Geojson file.

$python manage.py dumpdata --format=geojson > test.geojson

However, the geojson file does not contain pk (auto incremented integer). Is there any way to export the pk to the geojson file?


Solution

  • You could try creating a serializers.py in one of your apps, and subclass the geojson serializer from django.contrib.gis.

    In your app config, you will need to register your serializers module so that you can use it with the dumpdata command. You can see how the gis app does it here.