django1/django/contrib/gis/tests/geoapp/models.py

73 lines
1.5 KiB
Python
Raw Normal View History

from django.contrib.gis.db import models
from django.contrib.gis.tests.utils import mysql, spatialite
from django.utils.encoding import python_2_unicode_compatible
# MySQL spatial indices can't handle NULL geometries.
null_flag = not mysql
2013-11-03 04:12:09 +08:00
@python_2_unicode_compatible
class NamedModel(models.Model):
name = models.CharField(max_length=30)
objects = models.GeoManager()
class Meta:
abstract = True
app_label = 'geoapp'
def __str__(self):
return self.name
class Country(NamedModel):
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
2013-11-03 04:12:09 +08:00
class City(NamedModel):
point = models.PointField()
2013-11-03 04:12:09 +08:00
# This is an inherited model from City
class PennsylvaniaCity(City):
county = models.CharField(max_length=30)
founded = models.DateTimeField(null=True)
# TODO: This should be implicitly inherited.
2013-11-03 04:12:09 +08:00
objects = models.GeoManager()
class Meta:
app_label = 'geoapp'
2013-11-03 04:12:09 +08:00
class State(NamedModel):
poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
class Track(NamedModel):
line = models.LineStringField()
2013-11-03 04:12:09 +08:00
class Truth(models.Model):
val = models.BooleanField(default=False)
objects = models.GeoManager()
class Meta:
app_label = 'geoapp'
if not spatialite:
class Feature(NamedModel):
geom = models.GeometryField()
class MinusOneSRID(models.Model):
2013-11-03 05:02:56 +08:00
geom = models.PointField(srid=-1) # Minus one SRID.
objects = models.GeoManager()
class Meta:
app_label = 'geoapp'