| 1 |
from django.contrib.gis.db import models |
| 2 |
|
| 3 |
|
| 4 |
class SimpleModel(models.Model): |
| 5 |
class Meta: |
| 6 |
abstract = True |
| 7 |
|
| 8 |
|
| 9 |
class Location(SimpleModel): |
| 10 |
point = models.PointField() |
| 11 |
|
| 12 |
def __str__(self): |
| 13 |
return self.point.wkt |
| 14 |
|
| 15 |
|
| 16 |
class City(SimpleModel): |
| 17 |
name = models.CharField(max_length=50) |
| 18 |
state = models.CharField(max_length=2) |
| 19 |
location = models.ForeignKey(Location, models.CASCADE) |
| 20 |
|
| 21 |
def __str__(self): |
| 22 |
return self.name |
| 23 |
|
| 24 |
|
| 25 |
class AugmentedLocation(Location): |
| 26 |
extra_text = models.TextField(blank=True) |
| 27 |
|
| 28 |
|
| 29 |
class DirectoryEntry(SimpleModel): |
| 30 |
listing_text = models.CharField(max_length=50) |
| 31 |
location = models.ForeignKey(AugmentedLocation, models.CASCADE) |
| 32 |
|
| 33 |
|
| 34 |
class Parcel(SimpleModel): |
| 35 |
name = models.CharField(max_length=30) |
| 36 |
city = models.ForeignKey(City, models.CASCADE) |
| 37 |
center1 = models.PointField() |
| 38 |
# Throwing a curveball w/`db_column` here. |
| 39 |
center2 = models.PointField(srid=2276, db_column="mycenter") |
| 40 |
border1 = models.PolygonField() |
| 41 |
border2 = models.PolygonField(srid=2276) |
| 42 |
|
| 43 |
def __str__(self): |
| 44 |
return self.name |
| 45 |
|
| 46 |
|
| 47 |
class Author(SimpleModel): |
| 48 |
name = models.CharField(max_length=100) |
| 49 |
dob = models.DateField() |
| 50 |
|
| 51 |
|
| 52 |
class Article(SimpleModel): |
| 53 |
title = models.CharField(max_length=100) |
| 54 |
author = models.ForeignKey(Author, models.CASCADE, unique=True) |
| 55 |
|
| 56 |
|
| 57 |
class Book(SimpleModel): |
| 58 |
title = models.CharField(max_length=100) |
| 59 |
author = models.ForeignKey(Author, models.SET_NULL, related_name="books", null=True) |
| 60 |
|
| 61 |
|
| 62 |
class Event(SimpleModel): |
| 63 |
name = models.CharField(max_length=100) |
| 64 |
when = models.DateTimeField() |