2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-08-05 20:13:06 +02:00
|
|
|
|
2015-04-04 18:09:46 +02:00
|
|
|
from ..models import models
|
2015-02-10 16:07:44 +01:00
|
|
|
from ..utils import gisfield_may_be_null
|
|
|
|
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2014-01-01 11:01:46 +01:00
|
|
|
class NamedModel(models.Model):
|
2008-08-05 20:13:06 +02:00
|
|
|
name = models.CharField(max_length=30)
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2008-08-05 20:13:06 +02:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 10:17:41 +02:00
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2015-04-04 18:09:46 +02:00
|
|
|
required_db_features = ['gis_enabled']
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2013-10-17 10:17:41 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-08-05 20:13:06 +02:00
|
|
|
|
2014-01-01 18:37:52 +01:00
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
class Country(NamedModel):
|
|
|
|
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2013-10-17 10:17:41 +02:00
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
class City(NamedModel):
|
|
|
|
point = models.PointField()
|
2008-08-05 20:13:06 +02:00
|
|
|
|
2015-03-21 16:59:30 +01:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
2015-04-04 18:09:46 +02:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 16:59:30 +01:00
|
|
|
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2008-11-05 18:51:11 +01:00
|
|
|
# This is an inherited model from City
|
|
|
|
class PennsylvaniaCity(City):
|
|
|
|
county = models.CharField(max_length=30)
|
2011-09-10 00:34:23 +02:00
|
|
|
founded = models.DateTimeField(null=True)
|
2008-11-05 18:51:11 +01:00
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
# TODO: This should be implicitly inherited.
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2008-08-05 20:13:06 +02:00
|
|
|
objects = models.GeoManager()
|
2013-10-17 10:17:41 +02:00
|
|
|
|
2015-03-21 16:59:30 +01:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
2015-04-04 18:09:46 +02:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 16:59:30 +01:00
|
|
|
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
class State(NamedModel):
|
2014-08-21 18:47:57 +02:00
|
|
|
poly = models.PolygonField(null=gisfield_may_be_null) # Allowing NULL geometries here.
|
2013-10-17 10:17:41 +02:00
|
|
|
|
2015-03-21 16:59:30 +01:00
|
|
|
class Meta:
|
|
|
|
app_label = 'geoapp'
|
2015-04-04 18:09:46 +02:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 16:59:30 +01:00
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
|
|
|
|
class Track(NamedModel):
|
|
|
|
line = models.LineStringField()
|
2010-01-29 03:20:58 +01:00
|
|
|
|
2013-11-02 21:12:09 +01:00
|
|
|
|
2014-11-08 17:08:12 +01:00
|
|
|
class MultiFields(NamedModel):
|
|
|
|
city = models.ForeignKey(City)
|
|
|
|
point = models.PointField()
|
|
|
|
poly = models.PolygonField()
|
|
|
|
|
2015-03-21 17:38:23 +01:00
|
|
|
class Meta:
|
|
|
|
unique_together = ('city', 'point')
|
2015-04-04 18:09:46 +02:00
|
|
|
required_db_features = ['gis_enabled']
|
2015-03-21 17:38:23 +01:00
|
|
|
|
2014-11-08 17:08:12 +01:00
|
|
|
|
2012-03-02 23:32:22 +01:00
|
|
|
class Truth(models.Model):
|
2013-08-11 22:19:09 +02:00
|
|
|
val = models.BooleanField(default=False)
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2012-03-02 23:32:22 +01:00
|
|
|
objects = models.GeoManager()
|
|
|
|
|
2015-04-04 18:09:46 +02:00
|
|
|
class Meta:
|
|
|
|
required_db_features = ['gis_enabled']
|
|
|
|
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2014-08-19 18:47:23 +02:00
|
|
|
class Feature(NamedModel):
|
|
|
|
geom = models.GeometryField()
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2013-10-17 10:17:41 +02:00
|
|
|
|
2014-08-19 18:47:23 +02:00
|
|
|
class MinusOneSRID(models.Model):
|
|
|
|
geom = models.PointField(srid=-1) # Minus one SRID.
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2014-08-19 18:47:23 +02:00
|
|
|
objects = models.GeoManager()
|
2014-01-01 11:01:46 +01:00
|
|
|
|
2015-04-04 18:09:46 +02:00
|
|
|
class Meta:
|
|
|
|
required_db_features = ['gis_enabled']
|
|
|
|
|
2014-08-12 14:08:40 +02:00
|
|
|
|
|
|
|
class NonConcreteField(models.IntegerField):
|
|
|
|
|
|
|
|
def db_type(self, connection):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_attname_column(self):
|
|
|
|
attname, column = super(NonConcreteField, self).get_attname_column()
|
|
|
|
return attname, None
|
|
|
|
|
|
|
|
|
|
|
|
class NonConcreteModel(NamedModel):
|
|
|
|
non_concrete = NonConcreteField()
|
|
|
|
point = models.PointField(geography=True)
|