2021-08-23 18:30:02 +02:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class KonovaCode(models.Model):
|
|
|
|
"""
|
|
|
|
Representation of the OSIRIS Codelisten codes.
|
|
|
|
|
|
|
|
KonovaCodes will be updated using a command regularly to provide all codes, which are provided by the
|
|
|
|
Codelisten application itself. To reduce traffic, we store them in our own database.
|
|
|
|
"""
|
|
|
|
id = models.IntegerField(
|
|
|
|
primary_key=True,
|
|
|
|
help_text="AtomId; Identifies this code uniquely over all NatIT projects"
|
|
|
|
)
|
|
|
|
parent = models.ForeignKey(
|
|
|
|
"KonovaCode",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
short_name = models.CharField(
|
|
|
|
max_length=500,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
help_text="Short version of long name",
|
|
|
|
)
|
|
|
|
long_name = models.CharField(
|
|
|
|
max_length=1000,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
help_text="",
|
|
|
|
)
|
|
|
|
is_leaf = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text="Whether this code has children or not"
|
|
|
|
)
|
|
|
|
is_active = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text="Whether this code is archived or not"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.is_leaf and self.parent:
|
2021-08-24 09:31:12 +02:00
|
|
|
return "{} > {}".format(self.parent.long_name, self.long_name)
|
2021-08-23 18:30:02 +02:00
|
|
|
return self.long_name
|
|
|
|
|
|
|
|
|
|
|
|
class KonovaCodeList(models.Model):
|
|
|
|
"""
|
|
|
|
The codelist itself
|
|
|
|
"""
|
|
|
|
id = models.IntegerField(
|
|
|
|
primary_key=True,
|
|
|
|
help_text="List identifier",
|
|
|
|
)
|
|
|
|
codes = models.ManyToManyField(
|
|
|
|
KonovaCode,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
help_text="Codes for this list",
|
|
|
|
related_name="code_lists"
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.id)
|