summaryrefslogtreecommitdiffstats
path: root/core/models/caves.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-07-25 18:55:42 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2023-07-25 18:55:42 +0300
commit7d4ca5dae2134e7af7906176982855d810418b5a (patch)
tree9c7268894a545edd2a98de5af522392df4e7b0b0 /core/models/caves.py
parent3c78ab79ca14d71eb545fdb4e5aa641ad70d9786 (diff)
downloadtroggle-7d4ca5dae2134e7af7906176982855d810418b5a.tar.gz
troggle-7d4ca5dae2134e7af7906176982855d810418b5a.tar.bz2
troggle-7d4ca5dae2134e7af7906176982855d810418b5a.zip
Make robust against duplicate objects
Diffstat (limited to 'core/models/caves.py')
-rw-r--r--core/models/caves.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/core/models/caves.py b/core/models/caves.py
index d0520fb..5bef08c 100644
--- a/core/models/caves.py
+++ b/core/models/caves.py
@@ -311,12 +311,23 @@ class Entrance(TroggleModel):
def __str__(self):
return str(self.slug)
+ def single(self, station):
+ try:
+ single = SurvexStation.objects.get(name = station)
+ return single
+ except:
+ stations = SurvexStation.objects.filter(name = station)
+ print(f" # MULTIPLE stations found with same name '{station}' in Entrance {self}:")
+ for s in stations:
+ print(f" # {s.id=} - {s.name} {s.latlong()}") # .id is Django internal field, not one of ours
+ return stations[0]
+
def exact_location(self):
- return SurvexStation.objects.get(name = self.exact_station)
+ return self.single(self.exact_station)
def other_location(self):
- return SurvexStation.objects.get(name = self.other_station)
-
+ return self.single(self.other_station)
+
def find_location(self):
r = {"": "To be entered ", "?": "To be confirmed:", "S": "", "L": "Lost:", "R": "Refindable:"}[self.findability]
if self.tag_station:
@@ -376,7 +387,7 @@ class Entrance(TroggleModel):
return f[1]
def tag(self):
- return SurvexStation.objects.get(name = self.tag_station)
+ return self.single(self.tag_station)
def needs_surface_work(self):
return self.findability != "S" or not self.has_photo or self.marking != "T"