diff --git a/home/models/__init__.py b/home/models/__init__.py index 81109439..efae6a3c 100644 --- a/home/models/__init__.py +++ b/home/models/__init__.py @@ -4,3 +4,4 @@ from .intentionalwalk import IntentionalWalk from .contest import Contest from .race import Race +from .destination import Destination diff --git a/home/models/destination.py b/home/models/destination.py new file mode 100644 index 00000000..a145a57b --- /dev/null +++ b/home/models/destination.py @@ -0,0 +1,21 @@ +from django.db import models + + +class Destination(models.Model): + """ + Points of Interest ("destinations") + """ + + name = models.CharField(max_length=40, unique=True, help_text="Destination name") + place_id = models.CharField(max_length=256, blank=True, help_text="Place ID (Google Maps Platform)") + category = models.CharField(max_length=20, help_text="Destination category/type") + latitude = models.FloatField(max_length=40, unique=True, help_text="Geolocation latitude") + longitude = models.FloatField(max_length=40, unique=True, help_text="Geolocation longitude") + address = models.CharField(max_length=100, help_text="Street address") + zip = models.CharField(max_length=10, help_text="Zip code") + + created = models.DateTimeField(auto_now_add=True, help_text="Creation timestamp") + updated = models.DateTimeField(auto_now=True, help_text="Update timestamp") + + def __str__(self): + return f"" diff --git a/home/models/intentionalwalk.py b/home/models/intentionalwalk.py index 8d7879b4..d3a4c2f0 100644 --- a/home/models/intentionalwalk.py +++ b/home/models/intentionalwalk.py @@ -1,5 +1,7 @@ import time from django.db import models + +from home.models.destination import Destination from home.templatetags.format_helpers import m_to_mi @@ -17,6 +19,7 @@ class IntentionalWalk(models.Model): pause_time = models.FloatField(help_text="Total time paused (in seconds)") distance = models.FloatField(help_text="Total distance covered") device = models.ForeignKey("Device", on_delete=models.CASCADE, help_text="Device the data is coming from") + destination = models.ManyToManyField(Destination, help_text="Destinations along the walk") account = models.ForeignKey("Account", on_delete=models.CASCADE, help_text="Account the data is linked to") created = models.DateTimeField(auto_now_add=True, help_text="Record creation timestamp") diff --git a/home/models/intentionalwalk_destination.py b/home/models/intentionalwalk_destination.py new file mode 100644 index 00000000..1bef99a9 --- /dev/null +++ b/home/models/intentionalwalk_destination.py @@ -0,0 +1,14 @@ +from django.db import models + +from home.models.intentionalwalk import IntentionalWalk +from home.models.destination import Destination + +# blog/models.py +class IntentionalWalkDestination(models.Model): + intentional_walk = models.ForeignKey(IntentionalWalk, on_delete=models.CASCADE) + destination = models.ForeignKey(Destination, on_delete=models.CASCADE) + closest = models.FloatField(blank=True, help_text="Closest distance from destination (m)") + farthest = models.FloatField(blank=True, help_text="Farthest distance from destination (m)") + + class Meta: + unique_together = ('contributor', 'blog')