Pretty up models.

Pretty up import file.
This commit is contained in:
Tyrel Souza 2015-09-01 01:05:34 -04:00
parent b817aecd1e
commit e5eb602ec8
3 changed files with 54 additions and 7 deletions

View File

@ -50,12 +50,14 @@ class Command(BaseCommand):
"Haven't run across one that has multiple segments. "
"Contribute a patch if you have.")
elif isinstance(segments, dict):
# TODO: IF multiple import!
track = Track.objects.create(user=self.user,
start=start_time,
name=name)
points = segments['trkpt']
segment = Segment(track=track, time=points[0]['time'])
segment.save()
print len(points)
for pt in points:
Point.objects.create(segment=segment,
time=pt['time'],

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('tracking', '0005_segment_time'),
]
operations = [
migrations.AlterField(
model_name='point',
name='latitude',
field=models.DecimalField(max_digits=10, decimal_places=6),
),
migrations.AlterField(
model_name='point',
name='longitude',
field=models.DecimalField(max_digits=10, decimal_places=6),
),
]

View File

@ -13,6 +13,13 @@ class Track(models.Model):
def finish(self):
return self.segment_set.order_by("-time")[0].finish
def __str__(self):
return "[{user}] '{name}' from {start} to {finish}".format(
user=self.user.username,
name=self.name,
start=self.start,
finish=self.finish)
class Segment(models.Model):
track = models.ForeignKey(Track)
@ -23,10 +30,24 @@ class Segment(models.Model):
def finish(self):
return self.point_set.order_by("-time")[0].time
def __str__(self):
return "'{name}' Segment #{number} at {tme}".format(
name=self.track.name,
number=self.number,
tme=self.time)
class Point(models.Model):
time = models.DateTimeField()
latitude = models.DecimalField(max_digits=13, decimal_places=10)
longitude = models.DecimalField(max_digits=12, decimal_places=10)
latitude = models.DecimalField(max_digits=10, decimal_places=6)
longitude = models.DecimalField(max_digits=10, decimal_places=6)
elevation = models.DecimalField(max_digits=20, decimal_places=2)
segment = models.ForeignKey(Segment)
def __str__(self):
return "'{name}' ({lat},{lon}) -> {alt} on {time}".format(
lat=self.latitude,
lon=self.longitude,
alt=self.elevation,
time=self.time,
name=self.segment.track.name)