From af4bd9356f89c7e765df389f8522e6a39c0ea3c9 Mon Sep 17 00:00:00 2001 From: moanos Date: Fri, 31 May 2024 12:53:06 +0200 Subject: [PATCH] feat: Add function to calculate if a given position is within a given distance --- src/fellchensammlung/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index d037968..88fd615 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -178,6 +178,20 @@ class AdoptionNotice(models.Model): if len(photos) > 0: return photos[0] + def in_distance(self, position, max_distance, unknown_true=True): + """ + Returns a boolean indicating if the Location of the adoption notice is within a given distance to the position + + If the location is none, we by default return that the location is within the given distance + """ + if unknown_true and self.position is None: + return True + + distance = geo.calculate_distance_between_coordinates(self.position, position) + return distance < max_distance + + + class Animal(models.Model): MALE_NEUTERED = "M_N"