是的,它可以做到。我创建了两个模型,一个带有点,另一个带有非空间相关数据。使用 template_postgis。这是一些代码:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'pccs',
'USER': 'xxxxx',
'PASSWORD': 'xxxxx',
'HOST': 'localhost',
'PORT': '5432', # Set to empty string for default.
}
}
from django.contrib.gis.db import models
class Station(models.Model):
station_num = models.IntegerField("Station Number", max_length=4, primary_key=True)
station_name = models.CharField("Station Name", max_length=50)
station_type = models.CharField("Station Type", max_length=20, choices=TYPE_CHOICES)
geom = models.PointField(srid=4326)
objects = models.GeoManager()
def __unicode__(self):
return unicode(self.station_name)
class Meta:
verbose_name_plural = 'Monitoring Stations'
class Nutrient(models.Model):
station_num = models.ForeignKey(Station)
sample_date = models.DateField(editable=True)
#sample_depth = models.IntegerField("Sample Depth", max_length=4, default="1")
a = models.DecimalField("Temperature", max_digits=10, decimal_places=4)
...
o = models.DecimalField("ph", max_digits=10, decimal_places=4, blank=True, null=True)
def __unicode__(self):
return unicode(self.station_num_id)
class Meta:
verbose_name_plural = 'Water Sample Data'
希望这就是你要找的