Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Intentional Walks should have destinations #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions home/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .intentionalwalk import IntentionalWalk
from .contest import Contest
from .race import Race
from .destination import Destination
21 changes: 21 additions & 0 deletions home/models/destination.py
Original file line number Diff line number Diff line change
@@ -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"<Destination: {self.name}>"
3 changes: 3 additions & 0 deletions home/models/intentionalwalk.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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")

Expand Down
14 changes: 14 additions & 0 deletions home/models/intentionalwalk_destination.py
Original file line number Diff line number Diff line change
@@ -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')