|
1 from django.contrib.gis.db import models |
|
2 from django.contrib.localflavor.us.models import USStateField |
|
3 |
|
4 class Location(models.Model): |
|
5 point = models.PointField() |
|
6 objects = models.GeoManager() |
|
7 def __unicode__(self): return self.point.wkt |
|
8 |
|
9 class City(models.Model): |
|
10 name = models.CharField(max_length=50) |
|
11 state = USStateField() |
|
12 location = models.ForeignKey(Location) |
|
13 objects = models.GeoManager() |
|
14 def __unicode__(self): return self.name |
|
15 |
|
16 class AugmentedLocation(Location): |
|
17 extra_text = models.TextField(blank=True) |
|
18 objects = models.GeoManager() |
|
19 |
|
20 class DirectoryEntry(models.Model): |
|
21 listing_text = models.CharField(max_length=50) |
|
22 location = models.ForeignKey(AugmentedLocation) |
|
23 objects = models.GeoManager() |
|
24 |
|
25 class Parcel(models.Model): |
|
26 name = models.CharField(max_length=30) |
|
27 city = models.ForeignKey(City) |
|
28 center1 = models.PointField() |
|
29 # Throwing a curveball w/`db_column` here. |
|
30 center2 = models.PointField(srid=2276, db_column='mycenter') |
|
31 border1 = models.PolygonField() |
|
32 border2 = models.PolygonField(srid=2276) |
|
33 objects = models.GeoManager() |
|
34 def __unicode__(self): return self.name |
|
35 |
|
36 # These use the GeoManager but do not have any geographic fields. |
|
37 class Author(models.Model): |
|
38 name = models.CharField(max_length=100) |
|
39 objects = models.GeoManager() |
|
40 |
|
41 class Book(models.Model): |
|
42 title = models.CharField(max_length=100) |
|
43 author = models.ForeignKey(Author, related_name='books', null=True) |
|
44 objects = models.GeoManager() |