summaryrefslogtreecommitdiffstats
path: root/core/models.py
diff options
context:
space:
mode:
authorexpo <expo@expobox.potato.hut>2012-08-12 19:10:23 +0200
committerexpo <expo@expobox.potato.hut>2012-08-12 19:10:23 +0200
commit28047277f1fb0679c3b94bb5a14d2384a94cc27f (patch)
treeaef1c4569ab3807e5aed76512c42ae3cee9d0ca8 /core/models.py
parent5ff163efaa0c5c6d154b1f47991d41ec4abfccef (diff)
downloadtroggle-28047277f1fb0679c3b94bb5a14d2384a94cc27f.tar.gz
troggle-28047277f1fb0679c3b94bb5a14d2384a94cc27f.tar.bz2
troggle-28047277f1fb0679c3b94bb5a14d2384a94cc27f.zip
Started removing foreignkeys to caves, to achieve greater flexability. Some log book entries stuff may be broken. Add ability to make new caves and entrances via website.
Diffstat (limited to 'core/models.py')
-rw-r--r--core/models.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/core/models.py b/core/models.py
index ca4556e..1c86dd5 100644
--- a/core/models.py
+++ b/core/models.py
@@ -23,7 +23,8 @@ def get_related_by_wikilinks(wiki_text):
for wikilink in found:
qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
try:
- qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'],
+ cave_slugs = CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
+ qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
found_by__date__year = qmdict['year'],
number = qmdict['number'])
res.append(qm)
@@ -240,17 +241,29 @@ class LogbookEntry(TroggleModel):
#author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip.
# Re: the above- so this field should be "typist" or something, not "author". - AC 15 jun 09
#MJG wants to KILL THIS, as it is typically redundant with PersonTrip.is_logbook_entry_author, in the rare it was not redundanty and of actually interest it could be added to the text.
- title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
- cave = models.ForeignKey('Cave',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")
- text = models.TextField()
- slug = models.SlugField(max_length=50)
- filename= models.CharField(max_length=200,null=True)
+ title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
+ cave_slug = models.SlugField(max_length=50)
+ place = models.CharField(max_length=100,blank=True,null=True,help_text="Only use this if you haven't chosen a cave")
+ text = models.TextField()
+ slug = models.SlugField(max_length=50)
+ filename = models.CharField(max_length=200,null=True)
class Meta:
verbose_name_plural = "Logbook Entries"
# several PersonTrips point in to this object
ordering = ('-date',)
+
+ def __getattribute__(self, item):
+ if item == "cave": #Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey
+ return CaveSlug.objects.get(slug = self.cave_slug).cave
+ return super(LogbookEntry, self).__getattribute__(item)
+
+ def __init__(self, *args, **kwargs):
+ if "cave" in kwargs.keys():
+ if kwargs["cave"] is not None:
+ kwargs["cave_slug"] = CaveSlug.objects.get(cave = kwargs["cave"], primary = True).slug
+ kwargs.pop("cave")
+ return super(LogbookEntry, self).__init__(*args, **kwargs)
def isLogbookEntry(self): # Function used in templates
return True