mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 00:27:07 +00:00
CASCADE fixes in data model
This commit is contained in:
@@ -12,7 +12,11 @@ from django.urls import reverse
|
||||
|
||||
|
||||
class SurvexDirectory(models.Model):
|
||||
path = models.CharField(max_length=200)
|
||||
"""This relates a Cave to the primary SurvexFile which is the 'head' of the survex tree for
|
||||
that cave. Surely this could just be a property of Cave ? No. Several subdirectories
|
||||
all relate to the same Cave
|
||||
"""
|
||||
path = models.CharField(max_length=200)
|
||||
cave = models.ForeignKey("Cave", blank=True, null=True, on_delete=models.SET_NULL)
|
||||
primarysurvexfile = models.ForeignKey(
|
||||
"SurvexFile", related_name="primarysurvexfile", blank=True, null=True, on_delete=models.SET_NULL
|
||||
@@ -66,7 +70,10 @@ class SurvexFile(models.Model):
|
||||
|
||||
class SurvexStationLookUpManager(models.Manager):
|
||||
"""Don't know what this does,
|
||||
https://docs.djangoproject.com/en/dev/topics/db/managers/"""
|
||||
https://docs.djangoproject.com/en/dev/topics/db/managers/
|
||||
This changes the .objects thinggy to use a case-insensitive match name__iexact
|
||||
so that now SurvexStation.objects.lookup() works as a case-insensitive match
|
||||
"""
|
||||
def lookup(self, name):
|
||||
blocknames, sep, stationname = name.rpartition(".")
|
||||
return self.get(block=SurvexBlock.objects.lookup(blocknames), name__iexact=stationname)
|
||||
@@ -75,7 +82,7 @@ class SurvexStationLookUpManager(models.Manager):
|
||||
class SurvexStation(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
block = models.ForeignKey("SurvexBlock", null=True, on_delete=models.SET_NULL)
|
||||
objects = SurvexStationLookUpManager()
|
||||
objects = SurvexStationLookUpManager() # overwrites SurvexStation.objects
|
||||
x = models.FloatField(blank=True, null=True)
|
||||
y = models.FloatField(blank=True, null=True)
|
||||
z = models.FloatField(blank=True, null=True)
|
||||
@@ -101,18 +108,22 @@ class SurvexStation(models.Model):
|
||||
#
|
||||
# Single SurvexBlock
|
||||
#
|
||||
class SurvexBlockLookUpManager(models.Manager):
|
||||
"""Don't know what this does,
|
||||
https://docs.djangoproject.com/en/dev/topics/db/managers/ """
|
||||
def lookup(self, name):
|
||||
if name == "":
|
||||
blocknames = []
|
||||
else:
|
||||
blocknames = name.split(".")
|
||||
block = SurvexBlock.objects.get(parent=None, survexfile__path=settings.SURVEX_TOPNAME)
|
||||
for blockname in blocknames:
|
||||
block = SurvexBlock.objects.get(parent=block, name__iexact=blockname)
|
||||
return block
|
||||
# class SurvexBlockLookUpManager(models.Manager):
|
||||
# """Don't know what this does,
|
||||
# https://docs.djangoproject.com/en/dev/topics/db/managers/
|
||||
|
||||
# This changes the .objects_set thinggy to use a case-insensitive match name__iexact
|
||||
# so that now SurvexBlock.objects.lookup() works as a case-insensitive match UNUSED
|
||||
# """
|
||||
# def lookup(self, name):
|
||||
# if name == "":
|
||||
# blocknames = []
|
||||
# else:
|
||||
# blocknames = name.split(".")
|
||||
# # block = SurvexBlock.objects.get(parent=None, survexfile__path=settings.SURVEX_TOPNAME)
|
||||
# for blockname in blocknames:
|
||||
# block = SurvexBlock.objects.get(parent=block, name__iexact=blockname)
|
||||
# return block
|
||||
|
||||
|
||||
class SurvexBlock(models.Model):
|
||||
@@ -120,7 +131,7 @@ class SurvexBlock(models.Model):
|
||||
Multiple anonymous survex blocks are possible within the same surfex file
|
||||
"""
|
||||
|
||||
objects = SurvexBlockLookUpManager()
|
||||
# objects = SurvexBlockLookUpManager()
|
||||
name = models.CharField(max_length=100)
|
||||
title = models.CharField(max_length=200)
|
||||
parent = models.ForeignKey("SurvexBlock", blank=True, null=True, on_delete=models.SET_NULL)
|
||||
@@ -163,10 +174,13 @@ class SurvexBlock(models.Model):
|
||||
|
||||
|
||||
class SurvexPersonRole(models.Model):
|
||||
"""The CASCADE means that if a SurvexBlock or a Person is deleted, then the SurvexPersonRole
|
||||
is deleted too
|
||||
"""
|
||||
survexblock = models.ForeignKey("SurvexBlock", on_delete=models.CASCADE)
|
||||
# increasing levels of precision, Surely we only need survexblock and person now that we have no link to a logbook entry?
|
||||
personname = models.CharField(max_length=100)
|
||||
person = models.ForeignKey("Person", blank=True, null=True, on_delete=models.SET_NULL) # not needed
|
||||
person = models.ForeignKey("Person", blank=True, null=True, on_delete=models.CASCADE) # not needed
|
||||
personexpedition = models.ForeignKey("PersonExpedition", blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
Reference in New Issue
Block a user