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
commitecd5bbcb1dbb00cc0d39cdf80151f41c07c6c8b2 (patch)
tree0899e18f4b9ccbc63e2241c011af0090e09f415d /core/models.py
parent6d5babd3319fec50f404bf7ad044962bd1f192e9 (diff)
downloadtroggle-ecd5bbcb1dbb00cc0d39cdf80151f41c07c6c8b2.tar.gz
troggle-ecd5bbcb1dbb00cc0d39cdf80151f41c07c6c8b2.tar.bz2
troggle-ecd5bbcb1dbb00cc0d39cdf80151f41c07c6c8b2.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