File: models.py

package info (click to toggle)
python-django 1.4.5-1%2Bdeb7u16
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 44,168 kB
  • sloc: python: 140,205; xml: 659; makefile: 160; sh: 145; sql: 7
file content (50 lines) | stat: -rw-r--r-- 1,686 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from django.contrib.gis.db import models
from django.contrib.gis.tests.utils import mysql, spatialite

# MySQL spatial indices can't handle NULL geometries.
null_flag = not mysql

class Country(models.Model):
    name = models.CharField(max_length=30)
    mpoly = models.MultiPolygonField() # SRID, by default, is 4326
    objects = models.GeoManager()
    def __unicode__(self): return self.name

class City(models.Model):
    name = models.CharField(max_length=30)
    point = models.PointField()
    objects = models.GeoManager()
    def __unicode__(self): return self.name

# This is an inherited model from City
class PennsylvaniaCity(City):
    county = models.CharField(max_length=30)
    founded = models.DateTimeField(null=True)
    objects = models.GeoManager() # TODO: This should be implicitly inherited.

class State(models.Model):
    name = models.CharField(max_length=30)
    poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
    objects = models.GeoManager()
    def __unicode__(self): return self.name

class Track(models.Model):
    name = models.CharField(max_length=30)
    line = models.LineStringField()
    objects = models.GeoManager()
    def __unicode__(self): return self.name

class Truth(models.Model):
    val = models.BooleanField()
    objects = models.GeoManager()

if not spatialite:
    class Feature(models.Model):
        name = models.CharField(max_length=20)
        geom = models.GeometryField()
        objects = models.GeoManager()
        def __unicode__(self): return self.name

    class MinusOneSRID(models.Model):
        geom = models.PointField(srid=-1) # Minus one SRID.
        objects = models.GeoManager()