From dd09ca3810ea0798899870930c3efb388b776a7c Mon Sep 17 00:00:00 2001 From: lxf Date: Sat, 25 May 2019 15:10:38 +0000 Subject: made some changes to use new checkin model --- app/sightings/models.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/sightings') 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 -- cgit v1.2.3-70-g09d2