2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-14 21:47:12 +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()