File: models.py

package info (click to toggle)
python-django 3%3A3.2.19-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 56,696 kB
  • sloc: python: 264,418; javascript: 18,362; xml: 193; makefile: 178; sh: 43
file content (127 lines) | stat: -rw-r--r-- 3,054 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from django.contrib.gis.db import models


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

    class Meta:
        abstract = True

    def __str__(self):
        return self.name


class State(NamedModel):
    pass


class County(NamedModel):
    state = models.ForeignKey(State, models.CASCADE)
    mpoly = models.MultiPolygonField(srid=4269, null=True)  # Multipolygon in NAD83


class CountyFeat(NamedModel):
    poly = models.PolygonField(srid=4269)


class City(NamedModel):
    name_txt = models.TextField(default='')
    name_short = models.CharField(max_length=5)
    population = models.IntegerField()
    density = models.DecimalField(max_digits=7, decimal_places=1)
    dt = models.DateField()
    point = models.PointField()

    class Meta:
        app_label = 'layermap'


class Interstate(NamedModel):
    length = models.DecimalField(max_digits=6, decimal_places=2)
    path = models.LineStringField()

    class Meta:
        app_label = 'layermap'


# Same as `City` above, but for testing model inheritance.
class CityBase(NamedModel):
    population = models.IntegerField()
    density = models.DecimalField(max_digits=7, decimal_places=1)
    point = models.PointField()


class ICity1(CityBase):
    dt = models.DateField()

    class Meta(CityBase.Meta):
        pass


class ICity2(ICity1):
    dt_time = models.DateTimeField(auto_now=True)

    class Meta(ICity1.Meta):
        pass


class Invalid(models.Model):
    point = models.PointField()


class HasNulls(models.Model):
    uuid = models.UUIDField(primary_key=True, editable=False)
    geom = models.PolygonField(srid=4326, blank=True, null=True)
    datetime = models.DateTimeField(blank=True, null=True)
    integer = models.IntegerField(blank=True, null=True)
    num = models.FloatField(blank=True, null=True)
    boolean = models.BooleanField(blank=True, null=True)
    name = models.CharField(blank=True, null=True, max_length=20)


class DoesNotAllowNulls(models.Model):
    uuid = models.UUIDField(primary_key=True, editable=False)
    geom = models.PolygonField(srid=4326)
    datetime = models.DateTimeField()
    integer = models.IntegerField()
    num = models.FloatField()
    boolean = models.BooleanField()
    name = models.CharField(max_length=20)


# Mapping dictionaries for the models above.
co_mapping = {
    'name': 'Name',
    # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case).
    'state': {'name': 'State'},
    'mpoly': 'MULTIPOLYGON',  # Will convert POLYGON features into MULTIPOLYGONS.
}

cofeat_mapping = {
    'name': 'Name',
    'poly': 'POLYGON',
}

city_mapping = {
    'name': 'Name',
    'population': 'Population',
    'density': 'Density',
    'dt': 'Created',
    'point': 'POINT',
}

inter_mapping = {
    'name': 'Name',
    'length': 'Length',
    'path': 'LINESTRING',
}

has_nulls_mapping = {
    'geom': 'POLYGON',
    'uuid': 'uuid',
    'datetime': 'datetime',
    'name': 'name',
    'integer': 'integer',
    'num': 'num',
    'boolean': 'boolean',
}