Properly assigned app_label to GIS test models.

Used abstract inheritance to cut down on code repetition.
This commit is contained in:
Aymeric Augustin 2014-01-01 11:01:46 +01:00
parent a502bbb2f0
commit fecfd50300
8 changed files with 153 additions and 172 deletions

View File

@ -3,77 +3,53 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible @python_2_unicode_compatible
class SouthTexasCity(models.Model): class NamedModel(models.Model):
name = models.CharField(max_length=30)
objects = models.GeoManager()
class Meta:
abstract = True
app_label = 'distapp'
def __str__(self):
return self.name
class SouthTexasCity(NamedModel):
"City model on projected coordinate system for South Texas." "City model on projected coordinate system for South Texas."
name = models.CharField(max_length=30)
point = models.PointField(srid=32140) point = models.PointField(srid=32140)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class SouthTexasCityFt(NamedModel):
class SouthTexasCityFt(models.Model):
"Same City model as above, but U.S. survey feet are the units." "Same City model as above, but U.S. survey feet are the units."
name = models.CharField(max_length=30)
point = models.PointField(srid=2278) point = models.PointField(srid=2278)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class AustraliaCity(NamedModel):
class AustraliaCity(models.Model):
"City model for Australia, using WGS84." "City model for Australia, using WGS84."
name = models.CharField(max_length=30)
point = models.PointField() point = models.PointField()
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class CensusZipcode(NamedModel):
class CensusZipcode(models.Model):
"Model for a few South Texas ZIP codes (in original Census NAD83)." "Model for a few South Texas ZIP codes (in original Census NAD83)."
name = models.CharField(max_length=5) name = models.CharField(max_length=5)
poly = models.PolygonField(srid=4269) poly = models.PolygonField(srid=4269)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class SouthTexasZipcode(NamedModel):
class SouthTexasZipcode(models.Model):
"Model for a few South Texas ZIP codes." "Model for a few South Texas ZIP codes."
name = models.CharField(max_length=5) name = models.CharField(max_length=5)
poly = models.PolygonField(srid=32140, null=True) poly = models.PolygonField(srid=32140, null=True)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class Interstate(NamedModel):
class Interstate(models.Model):
"Geodetic model for U.S. Interstates." "Geodetic model for U.S. Interstates."
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
path = models.LineStringField() path = models.LineStringField()
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class SouthTexasInterstate(NamedModel):
class SouthTexasInterstate(models.Model):
"Projected model for South Texas Interstates." "Projected model for South Texas Interstates."
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
path = models.LineStringField(srid=32140)
objects = models.GeoManager()
def __str__(self):
return self.name

View File

@ -3,85 +3,63 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible @python_2_unicode_compatible
class City3D(models.Model): class NamedModel(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
point = models.PointField(dim=3)
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
abstract = True
app_label = 'geo3d'
def __str__(self): def __str__(self):
return self.name return self.name
@python_2_unicode_compatible class City3D(NamedModel):
class Interstate2D(models.Model): point = models.PointField(dim=3)
name = models.CharField(max_length=30)
class Interstate2D(NamedModel):
line = models.LineStringField(srid=4269) line = models.LineStringField(srid=4269)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class Interstate3D(NamedModel):
class Interstate3D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(dim=3, srid=4269) line = models.LineStringField(dim=3, srid=4269)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class InterstateProj2D(NamedModel):
class InterstateProj2D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(srid=32140) line = models.LineStringField(srid=32140)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class InterstateProj3D(NamedModel):
class InterstateProj3D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(dim=3, srid=32140) line = models.LineStringField(dim=3, srid=32140)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class Polygon2D(NamedModel):
class Polygon2D(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(srid=32140) poly = models.PolygonField(srid=32140)
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class Polygon3D(NamedModel):
class Polygon3D(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(dim=3, srid=32140) poly = models.PolygonField(dim=3, srid=32140)
class SimpleModel(models.Model):
objects = models.GeoManager() objects = models.GeoManager()
def __str__(self): class Meta:
return self.name abstract = True
app_label = 'geo3d'
class Point2D(models.Model): class Point2D(SimpleModel):
point = models.PointField() point = models.PointField()
objects = models.GeoManager()
class Point3D(models.Model): class Point3D(SimpleModel):
point = models.PointField(dim=3) point = models.PointField(dim=3)
objects = models.GeoManager()
class MultiPoint3D(models.Model): class MultiPoint3D(SimpleModel):
mpoint = models.MultiPointField(dim=3) mpoint = models.MultiPointField(dim=3)
objects = models.GeoManager()

View File

@ -7,8 +7,12 @@ from django.utils.encoding import python_2_unicode_compatible
class City(models.Model): class City(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
point = models.PointField() point = models.PointField()
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
app_label = 'geoadmin'
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -7,66 +7,66 @@ null_flag = not mysql
@python_2_unicode_compatible @python_2_unicode_compatible
class Country(models.Model): class NamedModel(models.Model):
name = models.CharField(max_length=30) 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 mpoly = models.MultiPolygonField() # SRID, by default, is 4326
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class City(NamedModel):
class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField() point = models.PointField()
objects = models.GeoManager()
def __str__(self):
return self.name
# This is an inherited model from City # This is an inherited model from City
class PennsylvaniaCity(City): class PennsylvaniaCity(City):
county = models.CharField(max_length=30) county = models.CharField(max_length=30)
founded = models.DateTimeField(null=True) founded = models.DateTimeField(null=True)
objects = models.GeoManager() # TODO: This should be implicitly inherited.
# TODO: This should be implicitly inherited.
objects = models.GeoManager()
class Meta:
app_label = 'geoapp'
@python_2_unicode_compatible class State(NamedModel):
class State(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here. poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
objects = models.GeoManager()
def __str__(self):
return self.name
@python_2_unicode_compatible class Track(NamedModel):
class Track(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField() line = models.LineStringField()
objects = models.GeoManager()
def __str__(self):
return self.name
class Truth(models.Model): class Truth(models.Model):
val = models.BooleanField(default=False) val = models.BooleanField(default=False)
objects = models.GeoManager() objects = models.GeoManager()
if not spatialite: class Meta:
@python_2_unicode_compatible app_label = 'geoapp'
class Feature(models.Model):
name = models.CharField(max_length=20)
geom = models.GeometryField() if not spatialite:
objects = models.GeoManager()
class Feature(NamedModel):
geom = models.GeometryField()
def __str__(self):
return self.name
class MinusOneSRID(models.Model): class MinusOneSRID(models.Model):
geom = models.PointField(srid=-1) # Minus one SRID. geom = models.PointField(srid=-1) # Minus one SRID.
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
app_label = 'geoapp'

View File

@ -3,31 +3,30 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible @python_2_unicode_compatible
class City(models.Model): class NamedModel(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
point = models.PointField(geography=True)
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
abstract = True
app_label = 'geogapp'
def __str__(self): def __str__(self):
return self.name return self.name
@python_2_unicode_compatible class City(NamedModel):
class Zipcode(models.Model): point = models.PointField(geography=True)
code = models.CharField(max_length=10)
class Zipcode(NamedModel):
poly = models.PolygonField(geography=True) poly = models.PolygonField(geography=True)
objects = models.GeoManager()
def __str__(self):
return self.code
@python_2_unicode_compatible class County(NamedModel):
class County(models.Model):
name = models.CharField(max_length=25)
state = models.CharField(max_length=20) state = models.CharField(max_length=20)
mpoly = models.MultiPolygonField(geography=True) mpoly = models.MultiPolygonField(geography=True)
objects = models.GeoManager()
def __str__(self): def __str__(self):
return ' County, '.join([self.name, self.state]) return ' County, '.join([self.name, self.state])

View File

@ -2,6 +2,7 @@ from django.contrib.gis.db import models
class AllOGRFields(models.Model): class AllOGRFields(models.Model):
f_decimal = models.FloatField() f_decimal = models.FloatField()
f_float = models.FloatField() f_float = models.FloatField()
f_int = models.IntegerField() f_int = models.IntegerField()
@ -13,3 +14,6 @@ class AllOGRFields(models.Model):
point = models.PointField() point = models.PointField()
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
app_label = 'inspectapp'

View File

@ -1,61 +1,75 @@
from django.contrib.gis.db import models from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible
class State(models.Model): @python_2_unicode_compatible
name = models.CharField(max_length=20) class NamedModel(models.Model):
name = models.CharField(max_length=25)
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
abstract = True
app_label = 'layermap'
class County(models.Model): def __str__(self):
name = models.CharField(max_length=25) return self.name
class State(NamedModel):
pass
class County(NamedModel):
state = models.ForeignKey(State) state = models.ForeignKey(State)
mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83 mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83
objects = models.GeoManager()
class CountyFeat(models.Model): class CountyFeat(NamedModel):
name = models.CharField(max_length=25)
poly = models.PolygonField(srid=4269) poly = models.PolygonField(srid=4269)
objects = models.GeoManager()
class City(models.Model): class City(NamedModel):
name = models.CharField(max_length=25)
name_txt = models.TextField(default='') name_txt = models.TextField(default='')
population = models.IntegerField() population = models.IntegerField()
density = models.DecimalField(max_digits=7, decimal_places=1) density = models.DecimalField(max_digits=7, decimal_places=1)
dt = models.DateField() dt = models.DateField()
point = models.PointField() point = models.PointField()
objects = models.GeoManager()
class Interstate(models.Model): class Interstate(NamedModel):
name = models.CharField(max_length=20)
length = models.DecimalField(max_digits=6, decimal_places=2) length = models.DecimalField(max_digits=6, decimal_places=2)
path = models.LineStringField() path = models.LineStringField()
objects = models.GeoManager()
# Same as `City` above, but for testing model inheritance. # Same as `City` above, but for testing model inheritance.
class CityBase(models.Model): class CityBase(NamedModel):
name = models.CharField(max_length=25)
population = models.IntegerField() population = models.IntegerField()
density = models.DecimalField(max_digits=7, decimal_places=1) density = models.DecimalField(max_digits=7, decimal_places=1)
point = models.PointField() point = models.PointField()
objects = models.GeoManager()
class ICity1(CityBase): class ICity1(CityBase):
dt = models.DateField() dt = models.DateField()
class Meta(CityBase.Meta):
pass
class ICity2(ICity1): class ICity2(ICity1):
dt_time = models.DateTimeField(auto_now=True) dt_time = models.DateTimeField(auto_now=True)
class Meta(ICity1.Meta):
pass
class Invalid(models.Model): class Invalid(models.Model):
point = models.PointField() point = models.PointField()
class Meta:
app_label = 'layermap'
# Mapping dictionaries for the models above. # Mapping dictionaries for the models above.
co_mapping = {'name': 'Name', co_mapping = {'name': 'Name',
'state': {'name': 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case). 'state': {'name': 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case).

View File

@ -2,21 +2,28 @@ from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible class SimpleModel(models.Model):
class Location(models.Model):
point = models.PointField()
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
abstract = True
app_label = 'relatedapp'
@python_2_unicode_compatible
class Location(SimpleModel):
point = models.PointField()
def __str__(self): def __str__(self):
return self.point.wkt return self.point.wkt
@python_2_unicode_compatible @python_2_unicode_compatible
class City(models.Model): class City(SimpleModel):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
state = models.CharField(max_length=2) state = models.CharField(max_length=2)
location = models.ForeignKey(Location) location = models.ForeignKey(Location)
objects = models.GeoManager()
def __str__(self): def __str__(self):
return self.name return self.name
@ -24,17 +31,20 @@ class City(models.Model):
class AugmentedLocation(Location): class AugmentedLocation(Location):
extra_text = models.TextField(blank=True) extra_text = models.TextField(blank=True)
objects = models.GeoManager() objects = models.GeoManager()
class Meta:
app_label = 'relatedapp'
class DirectoryEntry(models.Model):
class DirectoryEntry(SimpleModel):
listing_text = models.CharField(max_length=50) listing_text = models.CharField(max_length=50)
location = models.ForeignKey(AugmentedLocation) location = models.ForeignKey(AugmentedLocation)
objects = models.GeoManager()
@python_2_unicode_compatible @python_2_unicode_compatible
class Parcel(models.Model): class Parcel(SimpleModel):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
city = models.ForeignKey(City) city = models.ForeignKey(City)
center1 = models.PointField() center1 = models.PointField()
@ -42,26 +52,22 @@ class Parcel(models.Model):
center2 = models.PointField(srid=2276, db_column='mycenter') center2 = models.PointField(srid=2276, db_column='mycenter')
border1 = models.PolygonField() border1 = models.PolygonField()
border2 = models.PolygonField(srid=2276) border2 = models.PolygonField(srid=2276)
objects = models.GeoManager()
def __str__(self): def __str__(self):
return self.name return self.name
# These use the GeoManager but do not have any geographic fields. # These use the GeoManager but do not have any geographic fields.
class Author(models.Model): class Author(SimpleModel):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
dob = models.DateField() dob = models.DateField()
objects = models.GeoManager()
class Article(models.Model): class Article(SimpleModel):
title = models.CharField(max_length=100) title = models.CharField(max_length=100)
author = models.ForeignKey(Author, unique=True) author = models.ForeignKey(Author, unique=True)
objects = models.GeoManager()
class Book(models.Model): class Book(SimpleModel):
title = models.CharField(max_length=100) title = models.CharField(max_length=100)
author = models.ForeignKey(Author, related_name='books', null=True) author = models.ForeignKey(Author, related_name='books', null=True)
objects = models.GeoManager()