1
0
mirror of https://github.com/django/django.git synced 2024-12-27 19:46:22 +00:00
django/tests/gis_tests/geoapp/models.py

116 lines
2.6 KiB
Python
Raw Normal View History

from django.utils.encoding import python_2_unicode_compatible
from ..models import models
from ..utils import gisfield_may_be_null
2013-11-02 20:12:09 +00:00
@python_2_unicode_compatible
class NamedModel(models.Model):
name = models.CharField(max_length=30)
objects = models.GeoManager()
class Meta:
abstract = True
required_db_features = ['gis_enabled']
def __str__(self):
return self.name
class Country(NamedModel):
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
2013-11-02 20:12:09 +00:00
class CountryWebMercator(NamedModel):
mpoly = models.MultiPolygonField(srid=3857)
class City(NamedModel):
point = models.PointField()
class Meta:
app_label = 'geoapp'
required_db_features = ['gis_enabled']
2013-11-02 20:12:09 +00: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-02 20:12:09 +00:00
objects = models.GeoManager()
class Meta:
app_label = 'geoapp'
required_db_features = ['gis_enabled']
2013-11-02 20:12:09 +00:00
class State(NamedModel):
poly = models.PolygonField(null=gisfield_may_be_null) # Allowing NULL geometries here.
class Meta:
app_label = 'geoapp'
required_db_features = ['gis_enabled']
class Track(NamedModel):
line = models.LineStringField()
2013-11-02 20:12:09 +00:00
class MultiFields(NamedModel):
city = models.ForeignKey(City, models.CASCADE)
point = models.PointField()
poly = models.PolygonField()
class Meta:
required_db_features = ['gis_enabled']
class UniqueTogetherModel(models.Model):
city = models.CharField(max_length=30)
point = models.PointField()
class Meta:
unique_together = ('city', 'point')
required_db_features = ['gis_enabled', 'supports_geometry_field_unique_index']
class Truth(models.Model):
val = models.BooleanField(default=False)
objects = models.GeoManager()
class Meta:
required_db_features = ['gis_enabled']
class Feature(NamedModel):
geom = models.GeometryField()
class MinusOneSRID(models.Model):
geom = models.PointField(srid=-1) # Minus one SRID.
objects = models.GeoManager()
class Meta:
required_db_features = ['gis_enabled']
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)