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)