From 2b56eed75972ca4aac1fa4a302f1ffc9495c1798 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 20 Aug 2020 21:37:27 +0200 Subject: [PATCH] Added OSM map partial, Place model function and added it to home. --- lostplaces/lostplaces_app/models.py | 13 ++++ lostplaces/lostplaces_app/templates/home.html | 1 + .../templates/partials/osm_map.html | 67 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 lostplaces/lostplaces_app/templates/partials/osm_map.html diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index 907f3bc..209c3b4 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -55,6 +55,19 @@ class Place (models.Model): longitude = models.FloatField() description = models.TextField() + # Get center position of all LP-geocoordinates. + + def average_latlon(): + place_list = Place.objects.all() + amount = len(place_list) + longitude = 0 + latitude = 0 + + for place in place_list: + longitude += place.longitude + latitude += place.latitude + return (latitude / amount, longitude / amount) + def __str__(self): return self.name diff --git a/lostplaces/lostplaces_app/templates/home.html b/lostplaces/lostplaces_app/templates/home.html index 40894a6..1e229d5 100644 --- a/lostplaces/lostplaces_app/templates/home.html +++ b/lostplaces/lostplaces_app/templates/home.html @@ -7,6 +7,7 @@

Explore the latest locations

+ {% include 'partials/osm_map.html' %}