diff options
Diffstat (limited to 'app/birds/models.py')
-rw-r--r-- | app/birds/models.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/app/birds/models.py b/app/birds/models.py index e96a36c..dc2aa19 100644 --- a/app/birds/models.py +++ b/app/birds/models.py @@ -1,4 +1,5 @@ import datetime +from django.core.urlresolvers import reverse from django.template.defaultfilters import slugify from django.contrib.gis.db import models from django.contrib.auth.models import User @@ -29,7 +30,7 @@ class BirdClass(models.Model): class Meta: verbose_name_plural = 'Bird Class' - ordering = ["common_name",] + ordering = ["common_name", ] def __str__(self): return self.common_name @@ -47,15 +48,16 @@ class Bird(models.Model): return self.common_name def get_absolute_url(self): - return "/birds/%s" %(self.slug) + return reverse("birds:detail", kwargs={"slug": self.slug}) class Meta: - ordering = ["common_name",] + ordering = ["common_name", ] def save(self): self.slug = slugify(self.common_name[:50]) super(Bird, self).save() + class BirdAudio(models.Model): bird = models.ForeignKey(Bird, related_name='recordings') audio = models.FileField(upload_to='audio/birds/') @@ -64,14 +66,15 @@ class BirdAudio(models.Model): location = models.CharField(max_length=200, null=True, blank=True) link = models.CharField(max_length=450, null=True, blank=True) copyright = models.CharField(max_length=250, null=True, blank=True) - + class Meta: verbose_name_plural = 'Bird Audio' - ordering = ["bird",] + ordering = ["bird", ] def __str__(self): return self.bird.common_name + class BirdSighting(models.Model): bird = models.ForeignKey(Bird) point = models.PointField() @@ -104,12 +107,15 @@ class BirdSighting(models.Model): def latitude(self): '''Get the site's latitude.''' return self.point.y + def __str__(self): return self.bird.common_name def save(self): try: - self.location = Location.objects.filter(geometry__contains=self.point).get() + self.location = Location.objects.filter( + geometry__contains=self.point + ).get() except Location.DoesNotExist: raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) super(BirdSighting, self).save() |