diff --git a/tracking/management/commands/import_gpx.py b/tracking/management/commands/import_gpx.py index 649871d..86f2c2b 100644 --- a/tracking/management/commands/import_gpx.py +++ b/tracking/management/commands/import_gpx.py @@ -50,23 +50,25 @@ 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'], elevation=pt['ele'], latitude=pt['@lat'], longitude=pt['@lon']) - print "created Track <{0}> start: {1}, stop: {2}".format( - track.name, - track.start, - track.finish - ) + print "created Track <{0}> start: {1}, stop: {2}".format( + track.name, + track.start, + track.finish + ) def etree_to_dict(t): diff --git a/tracking/migrations/0006_auto_20150901_0054.py b/tracking/migrations/0006_auto_20150901_0054.py new file mode 100644 index 0000000..594b26a --- /dev/null +++ b/tracking/migrations/0006_auto_20150901_0054.py @@ -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), + ), + ] diff --git a/tracking/models.py b/tracking/models.py index 35fde22..6de8133 100644 --- a/tracking/models.py +++ b/tracking/models.py @@ -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)