2008-08-06 02:13:06 +08:00
|
|
|
from django.contrib.gis.db import models
|
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
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-08-06 02:13:06 +08:00
|
|
|
class Location(models.Model):
|
|
|
|
point = models.PointField()
|
|
|
|
objects = models.GeoManager()
|
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
|
2008-08-06 02:13:06 +08:00
|
|
|
class City(models.Model):
|
|
|
|
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)
|
|
|
|
objects = models.GeoManager()
|
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)
|
|
|
|
objects = models.GeoManager()
|
2012-08-12 18:32:08 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2008-12-06 09:52:14 +08:00
|
|
|
class DirectoryEntry(models.Model):
|
|
|
|
listing_text = models.CharField(max_length=50)
|
|
|
|
location = models.ForeignKey(AugmentedLocation)
|
|
|
|
objects = models.GeoManager()
|
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
|
2009-03-04 06:10:15 +08:00
|
|
|
class Parcel(models.Model):
|
|
|
|
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)
|
|
|
|
objects = models.GeoManager()
|
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.
|
|
|
|
class Author(models.Model):
|
|
|
|
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
|
|
|
objects = models.GeoManager()
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2010-07-21 03:05:46 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
author = models.ForeignKey(Author, unique=True)
|
|
|
|
objects = models.GeoManager()
|
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2009-06-03 12:49:16 +08:00
|
|
|
class Book(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
2009-06-30 00:31:21 +08:00
|
|
|
author = models.ForeignKey(Author, related_name='books', null=True)
|
2009-06-03 12:49:16 +08:00
|
|
|
objects = models.GeoManager()
|