From f34d70edd517af5b6066b5e15a1bef1431c0735e Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 27 Aug 2020 17:16:03 +0200 Subject: [PATCH 1/2] Division by zero fix --- lostplaces/lostplaces_app/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index a6d16fa..75c33f9 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -29,7 +29,7 @@ class Voucher(models.Model): Creation date is being set automatically during voucher creation. """ - code = models.CharField(unique=True, max_length=10) + code = models.CharField(unique=True, max_length=30) created = models.DateTimeField(auto_now_add=True) expires = models.DateField() @@ -60,8 +60,8 @@ class Place (models.Model): def average_latlon(place_list): amount = len(place_list) # Init fill values to prevent None - longitude = 0 - latitude = 0 + longitude = 1 + latitude = 1 for place in place_list: longitude += place.longitude From 55b8d167518beb0da1342a607b2842c7d45f752b Mon Sep 17 00:00:00 2001 From: reverend Date: Thu, 27 Aug 2020 17:17:28 +0200 Subject: [PATCH 2/2] No realy --- lostplaces/lostplaces_app/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index 75c33f9..d513bb0 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -60,13 +60,16 @@ class Place (models.Model): def average_latlon(place_list): amount = len(place_list) # Init fill values to prevent None - longitude = 1 - latitude = 1 + longitude = 0 + latitude = 0 - for place in place_list: - longitude += place.longitude - latitude += place.latitude - return (latitude / amount, longitude / amount) + if amount > 0: + for place in place_list: + longitude += place.longitude + latitude += place.latitude + return (latitude / amount, longitude / amount) + + return (latitude, longitude) def __str__(self): return self.name