summaryrefslogtreecommitdiff
path: root/app/birds/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/birds/models.py')
-rw-r--r--app/birds/models.py62
1 files changed, 61 insertions, 1 deletions
diff --git a/app/birds/models.py b/app/birds/models.py
index 3fb0c0f..2ba9451 100644
--- a/app/birds/models.py
+++ b/app/birds/models.py
@@ -1,11 +1,15 @@
import datetime
+from django.template.defaultfilters import slugify
from django.contrib.gis.db import models
+from django.contrib.auth.models import User
+from django.utils import timezone
from locations.models import Location
def get_upload_path(self, filename):
return "images/bird-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
+
# from http://aba.org/checklist/codes.html
ABA_CODES = (
(1, 'regular occurring - common'),
@@ -23,6 +27,7 @@ class BirdClass(models.Model):
class Meta:
verbose_name_plural = 'Bird Class'
+ ordering = ["common_name",]
def __str__(self):
return self.common_name
@@ -30,17 +35,72 @@ class BirdClass(models.Model):
class Bird(models.Model):
common_name = models.CharField(max_length=200)
+ slug = models.SlugField()
scientific_name = models.CharField(max_length=200)
code = models.IntegerField(choices=ABA_CODES, default=0)
bird_class = models.ForeignKey(BirdClass)
+ image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
def __str__(self):
return self.common_name
+ def get_absolute_url(self):
+ return "/birds/%s" %(self.slug)
+
+ class Meta:
+ 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/')
+ recorder = models.CharField(max_length=200, null=True, blank=True)
+ pub_date = models.DateTimeField()
+ 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",]
+
+ def __str__(self):
+ return self.bird.common_name
class BirdSighting(models.Model):
bird = models.ForeignKey(Bird)
point = models.PointField()
location = models.ForeignKey(Location)
- date = models.DateTimeField('Date')
+ date = models.DateTimeField('Date', default=timezone.now)
image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
+ seen_by = models.ManyToManyField(User)
+
+ class Meta:
+ verbose_name_plural = 'Bird Sighting'
+
+ @property
+ def state(self):
+ return self.location.state
+
+ @property
+ def country(self):
+ return self.location.state.country
+
+ @property
+ def region(self):
+ return self.location.state.country.lux_region
+
+ @property
+ def longitude(self):
+ '''Get the site's longitude.'''
+ return self.point.x
+
+ @property
+ def latitude(self):
+ '''Get the site's latitude.'''
+ return self.point.y
+ def __str__(self):
+ return self.bird.common_name