2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 07:40:19 +00:00

Remove CaveSLug as a Class. Now each Cave has only one slug for sure.

This commit is contained in:
2024-07-12 17:18:05 +02:00
parent a4783d2332
commit 24c5ba9711
8 changed files with 17 additions and 63 deletions

View File

@@ -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