File: models.py

package info (click to toggle)
python-django 3%3A5.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 61,236 kB
  • sloc: python: 361,585; javascript: 19,250; xml: 211; makefile: 182; sh: 28
file content (104 lines) | stat: -rw-r--r-- 2,262 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from django.contrib.gis.db import models

from ..utils import gisfield_may_be_null


class NamedModel(models.Model):
    name = models.CharField(max_length=30)

    class Meta:
        abstract = True

    def __str__(self):
        return self.name


class Country(NamedModel):
    mpoly = models.MultiPolygonField()  # SRID, by default, is 4326


class CountryWebMercator(NamedModel):
    mpoly = models.MultiPolygonField(srid=3857)


class City(NamedModel):
    point = models.PointField()

    class Meta:
        app_label = "geoapp"


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

    class Meta:
        app_label = "geoapp"


class State(NamedModel):
    poly = models.PolygonField(
        null=gisfield_may_be_null
    )  # Allowing NULL geometries here.

    class Meta:
        app_label = "geoapp"


class Track(NamedModel):
    line = models.LineStringField()


class MultiFields(NamedModel):
    city = models.ForeignKey(City, models.CASCADE)
    point = models.PointField()
    poly = models.PolygonField()


class UniqueTogetherModel(models.Model):
    city = models.CharField(max_length=30)
    point = models.PointField()

    class Meta:
        unique_together = ("city", "point")
        required_db_features = ["supports_geometry_field_unique_index"]


class Truth(models.Model):
    val = models.BooleanField(default=False)


class Feature(NamedModel):
    geom = models.GeometryField()


class ThreeDimensionalFeature(NamedModel):
    geom = models.GeometryField(dim=3)

    class Meta:
        required_db_features = {"supports_3d_storage"}


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


class NonConcreteField(models.IntegerField):
    def db_type(self, connection):
        return None

    def get_attname_column(self):
        attname, column = super().get_attname_column()
        return attname, None


class NonConcreteModel(NamedModel):
    non_concrete = NonConcreteField()
    point = models.PointField(geography=True)


class ManyPointModel(NamedModel):
    point1 = models.PointField()
    point2 = models.PointField()
    point3 = models.PointField(srid=3857)