For a cave, force users to enter are and have a unique URL. Cope better if area not defined

This commit is contained in:
Martin Green 2023-04-30 18:58:41 +01:00
parent 0a3a6934c4
commit 31a60ce85c

View File

@ -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)