2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

CASCADE on delete removed from key foregin keys

This commit is contained in:
Philip Sargent 2020-06-30 15:26:03 +01:00
parent be2b17ea85
commit 6b0275d035
2 changed files with 32 additions and 42 deletions

View File

@ -26,7 +26,7 @@ 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)
parent = models.ForeignKey('Area', blank=True, null=True,on_delete=models.CASCADE)
parent = models.ForeignKey('Area', blank=True, null=True,on_delete=models.SET_NULL)
def __str__(self):
if self.parent:
return str(self.parent) + " - " + str(self.short_name)
@ -202,17 +202,6 @@ class Cave(TroggleModel):
pass
return lowestareas[0]
# This seems to be peculiarly broken, and is now replaced for logbooks.
# def getCaveByReference(reference):
# areaname, code = reference.split("-", 1)
# area = Area.objects.get(short_name = areaname)
# foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
# #print((list(foundCaves)))
# if len(foundCaves) == 1:
# return foundCaves[0]
# else:
# return False
class OtherCaveName(TroggleModel):
name = models.CharField(max_length=160)
cave = models.ForeignKey(Cave,on_delete=models.CASCADE)
@ -415,8 +404,8 @@ class LogbookEntry(TroggleModel):
)
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.ld()
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.CASCADE)#MJG wants to KILL THIS (redundant information)
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.CASCADE) # yes this is double-
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)#MJG wants to KILL THIS (redundant information)
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.SET_NULL) # yes this is double-
title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
cave_slug = models.SlugField(max_length=50, blank=True, null=True)
place = models.CharField(max_length=100,blank=True, null=True,help_text="Only use this if you haven't chosen a cave")
@ -488,10 +477,10 @@ class LogbookEntry(TroggleModel):
class QM(TroggleModel):
# based on qm.csv in trunk/expoweb/1623/204 which has the fields:
#"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment"
found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True,on_delete=models.CASCADE )
ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',blank=True, null=True,on_delete=models.CASCADE)
#cave = models.ForeignKey(Cave,on_delete=models.CASCADE)
#expedition = models.ForeignKey(Expedition,on_delete=models.CASCADE)
found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True,on_delete=models.SET_NULL )
ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',blank=True, null=True,on_delete=models.SET_NULL)
#cave = models.ForeignKey(Cave,on_delete=models.SET_NULL)
#expedition = models.ForeignKey(Expedition,on_delete=models.SET_NULL)
number = models.IntegerField(help_text="this is the sequential number in the year", )
GRADE_CHOICES=(
@ -505,7 +494,7 @@ class QM(TroggleModel):
location_description = models.TextField(blank=True)
nearest_station_description = models.CharField(max_length=400,blank=True, null=True)
nearest_station_name = models.CharField(max_length=200,blank=True, null=True)
nearest_station = models.ForeignKey(SurvexStation,blank=True, null=True,on_delete=models.CASCADE)
nearest_station = models.ForeignKey(SurvexStation,blank=True, null=True,on_delete=models.SET_NULL)
area = models.CharField(max_length=100,blank=True, null=True)
completion_description = models.TextField(blank=True,null=True)
comment=models.TextField(blank=True,null=True)
@ -543,7 +532,7 @@ def get_scan_path(instance, filename):
class PersonTrip(TroggleModel):
personexpedition = models.ForeignKey("PersonExpedition",null=True,on_delete=models.CASCADE)
#expeditionday = models.ForeignKey("ExpeditionDay",on_delete=models.CASCADE)#MJG wants to KILL THIS (redundant information)
#expeditionday = models.ForeignKey("ExpeditionDay",on_delete=models.SET_NULL)#MJG wants to KILL THIS (redundant information)
#date = models.DateField() #MJG wants to KILL THIS (redundant information)
time_underground = models.FloatField(help_text="In decimal hours")
logbook_entry = models.ForeignKey(LogbookEntry,on_delete=models.CASCADE)
@ -552,9 +541,9 @@ class PersonTrip(TroggleModel):
# sequencing by person (difficult to solve locally)
#persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext',
#blank=True,null=True,on_delete=models.CASCADE)#MJG wants to KILL THIS (and use funstion persontrip_next_auto)
#blank=True,null=True,on_delete=models.SET_NULL)#MJG wants to KILL THIS (and use funstion persontrip_next_auto)
#persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev',
#blank=True,null=True,on_delete=models.CASCADE)#MJG wants to KILL THIS(and use funstion persontrip_prev_auto)
#blank=True,null=True,on_delete=models.SET_NULL)#MJG wants to KILL THIS(and use funstion persontrip_prev_auto)
def persontrip_next(self):
futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all()
@ -699,8 +688,10 @@ def GetCaveLookup():
Gcavelookup["2011-01-bs30"] = Gcavelookup["190"]
Gcavelookup["bs30"] = Gcavelookup["190"]
Gcavelookup["87"] = Gcavelookup["190"]
Gcavelookup["2011-01"] = Gcavelookup["190"]
Gcavelookup["quarriesd"] = Gcavelookup["2002-08"]
Gcavelookup["2002-x11"] = Gcavelookup["2005-08"]
Gcavelookup["2002-x12"] = Gcavelookup["2005-07"]
Gcavelookup["2002-x13"] = Gcavelookup["2005-06"]
@ -733,7 +724,6 @@ def GetCaveLookup():
if not Gcavelookup[id]:
pass
elif Gcavelookup[id].kataster_number:
#print(Gcavelookup[id], file=sys.stderr)
addmore[id] = Gcavelookup[id].kataster_number
elif Gcavelookup[id].unofficial_number:
addmore[id] = Gcavelookup[id].unofficial_number.lower()

View File

@ -9,8 +9,8 @@ from django.urls import reverse
class SurvexDirectory(models.Model):
path = models.CharField(max_length=200)
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE)
primarysurvexfile = models.ForeignKey('SurvexFile', related_name='primarysurvexfile', blank=True, null=True,on_delete=models.CASCADE)
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)
# could also include files in directory but not referenced
class Meta:
@ -24,8 +24,8 @@ class SurvexDirectory(models.Model):
class SurvexFile(models.Model):
path = models.CharField(max_length=200)
survexdirectory = models.ForeignKey("SurvexDirectory", blank=True, null=True,on_delete=models.CASCADE)
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE)
survexdirectory = models.ForeignKey("SurvexDirectory", blank=True, null=True,on_delete=models.SET_NULL)
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL)
class Meta:
ordering = ('id',)
@ -64,8 +64,8 @@ class SurvexStationLookUpManager(models.Manager):
class SurvexStation(models.Model):
name = models.CharField(max_length=100)
block = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE)
# equate = models.ForeignKey('SurvexEquate', blank=True, null=True,on_delete=models.CASCADE)
block = models.ForeignKey('SurvexBlock', null=True,on_delete=models.SET_NULL)
# equate = models.ForeignKey('SurvexEquate', blank=True, null=True,on_delete=models.SET_NULL)
objects = SurvexStationLookUpManager()
x = models.FloatField(blank=True, null=True)
y = models.FloatField(blank=True, null=True)
@ -99,17 +99,17 @@ class SurvexBlockLookUpManager(models.Manager):
class SurvexBlock(models.Model):
objects = SurvexBlockLookUpManager()
name = models.CharField(max_length=100)
parent = models.ForeignKey('SurvexBlock', blank=True, null=True,on_delete=models.CASCADE)
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE)
parent = models.ForeignKey('SurvexBlock', blank=True, null=True,on_delete=models.SET_NULL)
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL)
date = models.DateField(blank=True, null=True)
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.CASCADE)
expedition = models.ForeignKey('Expedition', blank=True, null=True,on_delete=models.CASCADE)
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)
expedition = models.ForeignKey('Expedition', blank=True, null=True,on_delete=models.SET_NULL)
survexfile = models.ForeignKey("SurvexFile", blank=True, null=True,on_delete=models.CASCADE)
survexfile = models.ForeignKey("SurvexFile", blank=True, null=True,on_delete=models.SET_NULL)
survexpath = models.CharField(max_length=200) # the path for the survex stations
scansfolder = models.ForeignKey("ScansFolder", null=True,on_delete=models.CASCADE)
scansfolder = models.ForeignKey("ScansFolder", null=True,on_delete=models.SET_NULL)
legsall = models.IntegerField(null=True) # summary data for this block
legssplay = models.IntegerField(null=True) # summary data for this block
@ -146,9 +146,9 @@ class SurvexBlock(models.Model):
return list(self.expeditionday.survexblock_set.all()).index(self)
class SurvexTitle(models.Model):
survexblock = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE)
survexblock = models.ForeignKey('SurvexBlock',null=True, on_delete=models.SET_NULL)
title = models.CharField(max_length=200) # needed by svxcavesingle.html template
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.CASCADE)
cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL)
#
# member of a SurvexBlock
@ -170,10 +170,10 @@ class SurvexPersonRole(models.Model):
nrole = models.CharField(choices=ROLE_CHOICES, max_length=200, blank=True, null=True)
# increasing levels of precision
personname = models.CharField(max_length=100)
person = models.ForeignKey('Person', blank=True, null=True,on_delete=models.CASCADE)
personexpedition = models.ForeignKey('PersonExpedition', blank=True, null=True,on_delete=models.CASCADE)
persontrip = models.ForeignKey('PersonTrip', blank=True, null=True,on_delete=models.CASCADE)
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.CASCADE)
person = models.ForeignKey('Person', blank=True, null=True,on_delete=models.SET_NULL)
personexpedition = models.ForeignKey('PersonExpedition', blank=True, null=True,on_delete=models.SET_NULL)
persontrip = models.ForeignKey('PersonTrip', blank=True, null=True,on_delete=models.SET_NULL)
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)
def __str__(self):
return str(self.person) + " - " + str(self.survexblock) + " - " + str(self.nrole)
@ -194,7 +194,7 @@ class ScansFolder(models.Model):
class SingleScan(models.Model):
ffile = models.CharField(max_length=200)
name = models.CharField(max_length=200)
scansfolder = models.ForeignKey("ScansFolder", null=True,on_delete=models.CASCADE)
scansfolder = models.ForeignKey("ScansFolder", null=True,on_delete=models.SET_NULL)
class Meta:
ordering = ('name',)