2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2015-04-05 00:09:46 +08:00
|
|
|
from ..models import models
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class SimpleModel(models.Model):
|
|
|
|
|
|
|
|
objects = models.GeoManager()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2015-04-05 00:09:46 +08:00
|
|
|
required_db_features = ['gis_enabled']
|
2014-01-01 18:01:46 +08:00
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2014-01-01 18:01:46 +08:00
|
|
|
class Location(SimpleModel):
|
2008-08-06 02:13:06 +08:00
|
|
|
point = models.PointField()
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.point.wkt
|
2008-08-06 02:13:06 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2014-01-01 18:01:46 +08:00
|
|
|
class City(SimpleModel):
|
2008-08-06 02:13:06 +08:00
|
|
|
name = models.CharField(max_length=50)
|
2012-12-25 06:10:40 +08:00
|
|
|
state = models.CharField(max_length=2)
|
2008-08-06 02:13:06 +08:00
|
|
|
location = models.ForeignKey(Location)
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2008-12-06 09:52:14 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2008-12-06 09:52:14 +08:00
|
|
|
class AugmentedLocation(Location):
|
|
|
|
extra_text = models.TextField(blank=True)
|
2014-01-01 18:01:46 +08:00
|
|
|
|
2008-12-06 09:52:14 +08:00
|
|
|
objects = models.GeoManager()
|
2012-08-12 18:32:08 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class DirectoryEntry(SimpleModel):
|
2008-12-06 09:52:14 +08:00
|
|
|
listing_text = models.CharField(max_length=50)
|
|
|
|
location = models.ForeignKey(AugmentedLocation)
|
2009-03-04 06:10:15 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2014-01-01 18:01:46 +08:00
|
|
|
class Parcel(SimpleModel):
|
2009-03-04 06:10:15 +08:00
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
city = models.ForeignKey(City)
|
|
|
|
center1 = models.PointField()
|
|
|
|
# Throwing a curveball w/`db_column` here.
|
2012-08-12 18:32:08 +08:00
|
|
|
center2 = models.PointField(srid=2276, db_column='mycenter')
|
2009-03-04 06:10:15 +08:00
|
|
|
border1 = models.PolygonField()
|
|
|
|
border2 = models.PolygonField(srid=2276)
|
2013-10-17 16:17:41 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2009-06-03 12:49:16 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2009-06-03 12:49:16 +08:00
|
|
|
# These use the GeoManager but do not have any geographic fields.
|
2014-01-01 18:01:46 +08:00
|
|
|
class Author(SimpleModel):
|
2009-06-03 12:49:16 +08:00
|
|
|
name = models.CharField(max_length=100)
|
2011-09-11 06:53:26 +08:00
|
|
|
dob = models.DateField()
|
2009-06-03 12:49:16 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Article(SimpleModel):
|
2010-07-21 03:05:46 +08:00
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
author = models.ForeignKey(Author, unique=True)
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2014-01-01 18:01:46 +08:00
|
|
|
class Book(SimpleModel):
|
2009-06-03 12:49:16 +08:00
|
|
|
title = models.CharField(max_length=100)
|
2009-06-30 00:31:21 +08:00
|
|
|
author = models.ForeignKey(Author, related_name='books', null=True)
|
2014-08-12 20:08:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Event(SimpleModel):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
when = models.DateTimeField()
|