summaryrefslogtreecommitdiff
path: root/app/sightings/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/sightings/models.py')
-rw-r--r--app/sightings/models.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/app/sightings/models.py b/app/sightings/models.py
index 3852b1c..7527615 100644
--- a/app/sightings/models.py
+++ b/app/sightings/models.py
@@ -198,9 +198,12 @@ class Sighting(models.Model):
if not self.point:
self.point = Sighting.objects.latest().point
try:
- self.location = Location.objects.filter(
- geometry__contains=self.point
- ).get()
+ self.location = Location.objects.filter(geometry__contains=self.point).get()
+ except Location.MultipleObjectsReturned:
+ for l in Location.objects.filter(geometry__contains=self.point):
+ if l.parent:
+ self.location = l
+ break
except Location.DoesNotExist:
raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
self.ap_common_name = self.ap.common_name