summaryrefslogtreecommitdiff
path: root/app/birds/models.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2015-05-15 13:39:36 +0000
committerluxagraf <sng@luxagraf.net>2015-05-15 13:39:36 +0000
commit7af56825e3bdf925853a5c4aafdcb0853125bc2c (patch)
tree6ed056f5b15e8741b77cdb2005147bc3bd6645ff /app/birds/models.py
parenta9901c02b97b3411dc6ad0f7a9d9c59e6a3b24de (diff)
made the birds admin a little slicker
Diffstat (limited to 'app/birds/models.py')
-rw-r--r--app/birds/models.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/birds/models.py b/app/birds/models.py
index 2ba9451..453e3fd 100644
--- a/app/birds/models.py
+++ b/app/birds/models.py
@@ -73,7 +73,7 @@ class BirdAudio(models.Model):
class BirdSighting(models.Model):
bird = models.ForeignKey(Bird)
point = models.PointField()
- location = models.ForeignKey(Location)
+ location = models.ForeignKey(Location, blank=True)
date = models.DateTimeField('Date', default=timezone.now)
image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
seen_by = models.ManyToManyField(User)
@@ -104,3 +104,10 @@ class BirdSighting(models.Model):
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()
+ 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()