summaryrefslogtreecommitdiffstats
path: root/core/models/caves.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/models/caves.py')
-rw-r--r--core/models/caves.py44
1 files changed, 7 insertions, 37 deletions
diff --git a/core/models/caves.py b/core/models/caves.py
index 3821387..0ede2b1 100644
--- a/core/models/caves.py
+++ b/core/models/caves.py
@@ -32,33 +32,15 @@ todo = """
- Can we rewrite things to eliminate the CaveSlug and objects? Surely
foreign keys work fine ?!
-- Why do we have CaveAndEntrance objects ? Surely entranceletter belong son the Entrance object?
+- Why do we have CaveAndEntrance objects ? Surely entranceletter belongs on the Entrance object?
- move the aliases list from the code and put into an editable file
- Restore constraint: unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
+ or replace by a unique 'slug' field, better.
"""
-class Area(TroggleModel):
- short_name = models.CharField(max_length=100)
- name = models.CharField(max_length=200, blank=True, null=True)
- description = models.TextField(blank=True, null=True)
- super = models.ForeignKey("Area", blank=True, null=True, on_delete=models.SET_NULL)
-
- def __str__(self):
- if self.super:
- return str(self.super) + " - " + str(self.short_name)
- else:
- return str(self.short_name)
-
- def kat_area(self):
- if self.short_name in ["1623", "1626", "1624", "1627"]:
- return self.short_name
- elif self.super:
- return self.super.kat_area()
-
-
class CaveAndEntrance(models.Model):
"""This class is ONLY used to create a FormSet for editing the cave and all its
entrances in one form.
@@ -82,7 +64,8 @@ class CaveAndEntrance(models.Model):
class Cave(TroggleModel):
# too much here perhaps,
- area = models.ManyToManyField(Area, blank=False)
+ areacode = models.CharField(max_length=4, blank=True, null=True) # could use models.IntegerChoices
+ subarea = models.CharField(max_length=10, blank=True, null=True) # 9, 8c etc.
depth = models.CharField(max_length=100, blank=True, null=True)
description_file = models.CharField(max_length=200, blank=True, null=True)
entrances = models.ManyToManyField("Entrance", through="CaveAndEntrance")
@@ -97,7 +80,7 @@ class Cave(TroggleModel):
notes = models.TextField(blank=True, null=True)
official_name = models.CharField(max_length=160)
references = models.TextField(blank=True, null=True)
- survex_file = models.CharField(max_length=100, blank=True, null=True) # should be a foreign key
+ survex_file = models.CharField(max_length=100, blank=True, null=True) # should be a foreign key?
survey = models.TextField(blank=True, null=True)
underground_centre_line = models.TextField(blank=True, null=True)
underground_description = models.TextField(blank=True, null=True)
@@ -192,12 +175,7 @@ class Cave(TroggleModel):
return qms # a QuerySet
def kat_area(self):
- try:
- for a in self.area.all():
- if a.kat_area():
- return a.kat_area()
- except:
- return ""
+ return self.areacode
def entrances(self):
return CaveAndEntrance.objects.filter(cave=self)
@@ -258,15 +236,7 @@ class Cave(TroggleModel):
return (filepath, content, "utf8")
def getArea(self):
- areas = self.area.all()
- lowestareas = list(areas)
- for area in areas:
- if area.super in areas:
- try:
- lowestareas.remove(area.super)
- except:
- pass
- return lowestareas[0]
+ return self.areacode
class Entrance(TroggleModel):
MARKING_CHOICES = (