Error when using GeoDjango with SpatiaLite on Ubuntu
I'm trying to get GeoDjango running on SpatiaLite on Ubuntu 11.04, and even with a very minimal setup, I'm hitting a strange error. Saving an instance of a model with geo-fields works, but loading it again fails with an exception:
Error encountered checking Geometry returned from GEOS C function "GEOSWKBReader_read_r".
relevant parts of my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': '/tmp/test.db',
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.gis',
'testapp',
)
testapp.models
:
from django.contrib.gis.db import models
class TestModel(models.Model):
name = models.CharField(max_length=10)
location = models.PointField()
testapp.admin
from django.contrib.gis import admin
from testapp.models import TestModel
ad开发者_运维百科min.site.register(TestModel, admin.OSMGeoAdmin)
/edit: the same exact code works without problems on PostgreSQL/postgis
OK, I found the problem myself: I forgot to use models.GeoManager
as the default manager. This fixes my problem:
class TestModel(models.Model):
name = models.CharField(max_length=10)
location = models.PointField()
objects = models.GeoManager()
精彩评论