1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import datetime
from django.contrib.gis.db import models
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'),
(2, 'regular occurring - less common'),
(3, 'rare'),
(4, 'casual'),
(5, 'accidental'),
(6, 'Cannot be found'),
)
class BirdClass(models.Model):
common_name = models.CharField(max_length=200)
scientific_name = models.CharField(max_length=200)
class Meta:
verbose_name_plural = 'Bird Class'
def __str__(self):
return self.common_name
class Bird(models.Model):
common_name = models.CharField(max_length=200)
scientific_name = models.CharField(max_length=200)
code = models.IntegerField(choices=ABA_CODES, default=0)
bird_class = models.ForeignKey(BirdClass)
def __str__(self):
return self.common_name
class BirdSighting(models.Model):
bird = models.ForeignKey(Bird)
point = models.PointField()
location = models.ForeignKey(Location)
date = models.DateTimeField('Date')
image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
|