diff --git a/parsers/survex.py b/parsers/survex.py index 3deef71..8fc7e24 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -12,7 +12,7 @@ from django.utils.timezone import get_current_timezone from django.utils.timezone import make_aware import troggle.settings as settings -from troggle.core.models.caves import Entrance, QM, LogbookEntry +from troggle.core.models.caves import Cave, Entrance, QM, LogbookEntry from troggle.core.utils import get_process_memory, chaosmonkey from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.logbooks import GetCaveLookup @@ -1446,9 +1446,14 @@ def FindAndLoadSurvex(survexblockroot): def MakeSurvexFileRoot(): """Returns a file_object.path = SURVEX_TOPNAME associated with directory_object.path = SURVEX_DATA """ + # find a cave, any cave.. + c = Cave.objects.all() + fileroot = SurvexFile(path=settings.SURVEX_TOPNAME, cave=None) fileroot.save() - directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=None, primarysurvexfile=fileroot) + directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=c[0], primarysurvexfile=fileroot) + # MariaDB doesn't like this hack. Complains about non-null cave_id EVEN THOUGH our model file says this is OK: + # cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL) directoryroot.save() fileroot.survexdirectory = directoryroot # i.e. SURVEX_DATA/SURVEX_TOPNAME fileroot.save() # mutually dependent objects need a double-save like this