jsondjangogisgeodjangodjango-fixtures

What is the format for a PointField in a django fixture?


Suppose I have the following django model:

from django.db import models
from django.contrib.gis.db import models

class Location(models.Model):
    name = models.CharField(max_length=200)
    point = models.PointField()

And I want to load the PointField from a fixture. What is the format of the point field for a json fixture?

[
    {
    "model": "myapp.Location",
    "pk": 1,
    "fields": {
        "name": "Location Number 1",
        "point": "???",
    }
  }
]

Solution

  • It appears to use the Well-known text (WKT) format

    For example, the following worked with python manage.py loaddata myfixture.json:

    [
        {
        "model": "myapp.Location",
        "pk": 1,
        "fields": {
            "name": "Location Number 1",
            "point": "POINT (30 10)",
        }
      }
    ]
    

    This successfully imported into postgresql database column with the type point geometry(Point,4326).

    If you were using another type such as a PolygonField, then presumably the format would be for example:

    POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))