models.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from django.contrib.gis.db import models
  2. from django.contrib.gis.tests.utils import mysql, spatialite
  3. from django.utils.encoding import python_2_unicode_compatible
  4. # MySQL spatial indices can't handle NULL geometries.
  5. null_flag = not mysql
  6. @python_2_unicode_compatible
  7. class NamedModel(models.Model):
  8. name = models.CharField(max_length=30)
  9. objects = models.GeoManager()
  10. class Meta:
  11. abstract = True
  12. app_label = 'geoapp'
  13. def __str__(self):
  14. return self.name
  15. class Country(NamedModel):
  16. mpoly = models.MultiPolygonField() # SRID, by default, is 4326
  17. class City(NamedModel):
  18. point = models.PointField()
  19. # This is an inherited model from City
  20. class PennsylvaniaCity(City):
  21. county = models.CharField(max_length=30)
  22. founded = models.DateTimeField(null=True)
  23. # TODO: This should be implicitly inherited.
  24. objects = models.GeoManager()
  25. class Meta:
  26. app_label = 'geoapp'
  27. class State(NamedModel):
  28. poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
  29. class Track(NamedModel):
  30. line = models.LineStringField()
  31. class Truth(models.Model):
  32. val = models.BooleanField(default=False)
  33. objects = models.GeoManager()
  34. class Meta:
  35. app_label = 'geoapp'
  36. if not spatialite:
  37. class Feature(NamedModel):
  38. geom = models.GeometryField()
  39. class MinusOneSRID(models.Model):
  40. geom = models.PointField(srid=-1) # Minus one SRID.
  41. objects = models.GeoManager()
  42. class Meta:
  43. app_label = 'geoapp'