From 24c5ba97111428f0ee43d5633b278dc1a0c055c0 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 12 Jul 2024 17:18:05 +0200 Subject: Remove CaveSLug as a Class. Now each Cave has only one slug for sure. --- core/models/logbooks.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'core/models/logbooks.py') diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 1ffe55d..d8b4d93 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -10,34 +10,19 @@ from django.template import loader import settings from troggle.core.models.troggle import Expedition, TroggleModel + """The model declarations LogBookEntry, PersonLogEntry, QM """ todo = """ -- Can we rewrite things to eliminate the CaveSlug and objects? No - Surely foreign keys work fine ?! No Foreign keys do not allow for there being multiple ways to refer to a cave, eg 1623-1999-03 aka 1623-204 Having slugs allows for much more loose coupling to caves, which removes alot of the need to reset the database, which interupts work flow. It also means we do not have to be creating temporary cave objects in the database, where we do not have the underlying file in cave_data. - - To Do move Cave Slug back to troggle.core.models """ -class CaveSlug(models.Model): - """Moved here to avoid nasty cyclic import error - CASCADE means that if the Cave is deleted, this is too - """ - - cave = models.ForeignKey("Cave", on_delete=models.CASCADE) - slug = models.SlugField(max_length=50, unique=True) - primary = models.BooleanField(default=False) - - def __str__(self): - return f"{self.slug}: {self.cave}" - class LogbookEntry(TroggleModel): """Single parsed entry from Logbook @@ -48,7 +33,7 @@ class LogbookEntry(TroggleModel): ) expedition = models.ForeignKey(Expedition, blank=True, null=True, on_delete=models.CASCADE) title = models.CharField(max_length=200) - cave_slug = models.SlugField(max_length=50, blank=True, null=True) + cave = models.ForeignKey("Cave", blank=True, null=True, on_delete=models.SET_NULL) place = models.CharField( max_length=100, blank=True, null=True, help_text="Only use this if you haven't chosen a cave" ) @@ -62,10 +47,6 @@ class LogbookEntry(TroggleModel): # several PersonLogEntrys point in to this object ordering = ("-date",) - def cave(self): # Why didn't he just make this a foreign key to Cave ? - c = CaveSlug.objects.get(slug=self.cave_slug, primary=True).cave - return c - def isLogbookEntry(self): # Function used in templates return True -- cgit v1.2.3