From 31a60ce85c07fd37d0f6c52f33cedbcaaf17bd13 Mon Sep 17 00:00:00 2001 From: Martin Green Date: Sun, 30 Apr 2023 18:58:41 +0100 Subject: [PATCH] For a cave, force users to enter are and have a unique URL. Cope better if area not defined --- core/models/caves.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/models/caves.py b/core/models/caves.py index 1155f81..91453fc 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -81,7 +81,7 @@ class CaveAndEntrance(models.Model): class Cave(TroggleModel): # too much here perhaps, - area = models.ManyToManyField(Area, blank=True) + area = models.ManyToManyField(Area, blank=False) 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") @@ -101,7 +101,7 @@ class Cave(TroggleModel): underground_centre_line = models.TextField(blank=True, null=True) underground_description = models.TextField(blank=True, null=True) unofficial_number = models.CharField(max_length=60, blank=True, null=True) - url = models.CharField(max_length=200, blank=True, null=True) + url = models.CharField(max_length=200, blank=True, null=True, unique = True) # class Meta: # unique_together = (("area", "kataster_number"), ("area", "unofficial_number")) @@ -188,9 +188,12 @@ class Cave(TroggleModel): return qms # a QuerySet def kat_area(self): - for a in self.area.all(): - if a.kat_area(): - return a.kat_area() + try: + for a in self.area.all(): + if a.kat_area(): + return a.kat_area() + except: + return "" def entrances(self): return CaveAndEntrance.objects.filter(cave=self)