-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
134 lines (94 loc) · 6.43 KB
/
models.py
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
128
129
130
131
132
133
134
from tabnanny import verbose
from django.contrib.gis.db import models
import diana.abstract.models as abstract
import diana.abstract.mixins as mixins
from django.utils.translation import gettext_lazy as _
from diana.storages import OriginalFileStorage
from diana.abstract.models import get_original_path
AGE_CHOICES = (
('O', 'Old'),
('Y', 'Young'),
)
class Informant(abstract.AbstractBaseModel, mixins.GenderedMixin):
custom_id = models.CharField(max_length=256, unique=True, blank=True, null=True, verbose_name=_("custom ID"), help_text=_("An ID of the informant provided by the researcher."))
age = models.CharField(max_length=1, choices=AGE_CHOICES ,blank=True, null=True, verbose_name=_("age"), help_text=_("The approximate age of the informant."))
note = models.TextField(null=True, blank=True, verbose_name=_("note"), help_text=_("Researcher's note on informant."))
def __str__(self) -> str:
return self.custom_id
class Period(abstract.AbstractTagModel):
start_year = models.PositiveSmallIntegerField(blank=True, null=True, verbose_name=_("start year"), help_text=_("An approximate start year, if applicable."))
end_year = models.PositiveSmallIntegerField(blank=True, null=True, verbose_name=_("end year"), help_text=_("An approximate end year, if applicable."))
def __str__(self) -> str:
return self.text
class PlaceType(abstract.AbstractTagModel):
def __str__(self) -> str:
return self.text
class Meta:
verbose_name = _("place type")
verbose_name_plural = _("place types")
class Language(abstract.AbstractBaseModel):
name = models.CharField(max_length=512, blank=True, null=True, verbose_name=_("name"))
abbreviation = models.CharField(max_length=8, blank=True, null=True, verbose_name=_("abbreviation"))
class Meta:
verbose_name = _("language")
verbose_name_plural = _("languages")
def __str__(self) -> str:
return self.name
class PlaceOfInterest(abstract.AbstractBaseModel):
corrected = models.BooleanField(default=False, verbose_name=_("corrected"))
geometry = models.GeometryField(verbose_name=_("geometry"), blank=True, null=True)
description = models.TextField(null=True, blank=True, verbose_name=_("description"))
comment = models.TextField(null=True, blank=True, verbose_name=_("comment"))
type = models.ForeignKey(PlaceType, on_delete=models.PROTECT, verbose_name=_("type of place"), help_text=_("The type of place of interest"))
#parent place
is_iconic = models.BooleanField(default=False, verbose_name=_("is iconic"))
is_existing = models.BooleanField(default=False, verbose_name=_("is existing"))
is_private = models.BooleanField(default=False, verbose_name=_("is private"))
parent_place = models.ForeignKey('self', on_delete=models.PROTECT, help_text=_("The parent of place"), blank=True, null=True)
def __str__(self) -> str:
ns = ", ".join([f"{n.text}" for n in self.names.all()]).rstrip()
return f"{ns}" if ns else f"{self.id}"
class Meta:
verbose_name = _("place of interest")
verbose_name_plural = _("places of interest")
class Name(abstract.AbstractBaseModel):
languages = models.ManyToManyField(Language, blank=True, verbose_name=_("language"), related_name="%(class)s_names")
text = models.CharField(max_length=2028, blank=True, null=True, verbose_name=_("text"))
period = models.ForeignKey(Period, null=True, blank=True, on_delete=models.PROTECT, verbose_name=_("period"), help_text=_("An approximate periodization of the name."))
informants = models.ManyToManyField(Informant, blank=True, verbose_name=_("informants"), help_text=_("List of informants attesting to the name."), related_name="%(class)s_names")
note = models.TextField(null=True, blank=True, verbose_name=_("note"), help_text=_("Researcher's note on the name."))
referent = models.ForeignKey(PlaceOfInterest, on_delete=models.CASCADE, verbose_name=_("referent"), help_text=_("The street with this name."), related_name="names")
class Meta:
verbose_name = _("name")
verbose_name_plural = _("names")
def __str__(self) -> str:
return f"{self.text}"
class Author(abstract.AbstractBaseModel):
name = models.CharField(max_length=2028, verbose_name=_("name"))
def __str__(self) -> str:
return self.name
class Image(abstract.AbstractTIFFImageModel):
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_("general.title"))
place_of_interest = models.ForeignKey(PlaceOfInterest, null=True, blank=True, on_delete=models.CASCADE, related_name="images")
description = models.TextField(null=True, blank=True)
authors = models.ManyToManyField(Author, blank=True, related_name="images")
informants = models.ManyToManyField(Informant, blank=True, related_name="images", verbose_name=_("informants"), help_text=_("List of informants attesting to the name."))
def __str__(self) -> str:
return f"{self.title}"
class Text(abstract.AbstractBaseModel):
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_("title"))
place_of_interest = models.ForeignKey(PlaceOfInterest, null=True, blank=True, on_delete=models.CASCADE, related_name="texts")
text = models.TextField(null=True, blank=True, verbose_name=_("text"))
authors = models.ManyToManyField(Author, blank=True, related_name="texts")
informants = models.ManyToManyField(Informant, blank=True, related_name="texts", verbose_name=_("informants"), help_text=_("List of informants attesting to the name."))
def __str__(self) -> str:
return f"{self.title}"
class Document(abstract.AbstractBaseModel):
title = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_("document title"))
place_of_interest = models.ForeignKey(PlaceOfInterest, null=True, blank=True, on_delete=models.CASCADE, related_name="documents")
filename = models.FileField(null=True, blank=True, storage=OriginalFileStorage, upload_to=get_original_path, verbose_name=_("file"))
text = models.TextField(null=True, blank=True, verbose_name=_("document text"))
authors = models.ManyToManyField(Author, blank=True, related_name="document")
informants = models.ManyToManyField(Informant, blank=True, related_name="document", verbose_name=_("document informants"), help_text=_("List of informants attesting to the document."))
def __str__(self) -> str:
return f"{self.title}"