From a6025dee31ce8d40a47f1390d85532d3ed81fe5c Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 18 Nov 2024 06:42:36 +0100 Subject: [PATCH] fix: Switches DecimalFields to FloatFields in GPSPoint Converts battery, accuracy, speed, and bearing fields from DecimalField to FloatField in GPSPoint model for improved performance and simplified operations. Updates migration to reflect these changes, ensuring consistency across the database. --- gpslog/migrations/0001_initial.py | 98 +++++++++++++++++++++++-------- gpslog/models.py | 12 ++-- 2 files changed, 76 insertions(+), 34 deletions(-) diff --git a/gpslog/migrations/0001_initial.py b/gpslog/migrations/0001_initial.py index d5fcc22..59361be 100644 --- a/gpslog/migrations/0001_initial.py +++ b/gpslog/migrations/0001_initial.py @@ -1,10 +1,10 @@ -# Generated by Django 4.1.1 on 2022-09-09 16:07 +# Generated by Django 5.0.6 on 2024-11-18 05:40 -from django.conf import settings import django.contrib.gis.db.models.fields -from django.db import migrations, models import django.db.models.deletion import uuid +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): @@ -17,38 +17,84 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='GPSTrack', + name="GPSTrack", fields=[ - ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ( + "id", + models.UUIDField( + default=uuid.uuid4, primary_key=True, serialize=False + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), ], ), migrations.CreateModel( - name='GPSToken', + name="GPSToken", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(blank=True, max_length=128, null=True)), - ('token', models.UUIDField(default=uuid.uuid4)), - ('read', models.BooleanField(default=False)), - ('write', models.BooleanField(default=False)), - ('history', models.BooleanField(default=False)), - ('track', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gpslog.gpstrack')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(blank=True, max_length=128, null=True)), + ("token", models.UUIDField(default=uuid.uuid4)), + ("read", models.BooleanField(default=False)), + ("write", models.BooleanField(default=False)), + ("history", models.BooleanField(default=False)), + ( + "track", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="gpslog.gpstrack", + ), + ), ], ), migrations.CreateModel( - name='GPSPoint', + name="GPSPoint", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('point', django.contrib.gis.db.models.fields.PointField(srid=4326)), - ('timestamp', models.DateTimeField()), - ('battery', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)), - ('accuracy', models.DecimalField(blank=True, decimal_places=32, max_digits=64, null=True)), - ('speed', models.DecimalField(blank=True, decimal_places=32, max_digits=64, null=True)), - ('bearing', models.DecimalField(blank=True, decimal_places=61, max_digits=64, null=True)), - ('satellites', models.IntegerField(blank=True, null=True)), - ('user_agent', models.TextField(blank=True, null=True)), - ('token', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='gpslog.gpstoken')), - ('track', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gpslog.gpstrack')), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("point", django.contrib.gis.db.models.fields.PointField(srid=4326)), + ("timestamp", models.DateTimeField()), + ("battery", models.FloatField(blank=True, null=True)), + ("accuracy", models.FloatField(blank=True, null=True)), + ("speed", models.FloatField(blank=True, null=True)), + ("bearing", models.FloatField(blank=True, null=True)), + ("satellites", models.IntegerField(blank=True, null=True)), + ("user_agent", models.TextField(blank=True, null=True)), + ( + "token", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="gpslog.gpstoken", + ), + ), + ( + "track", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="gpslog.gpstrack", + ), + ), ], ), ] diff --git a/gpslog/models.py b/gpslog/models.py index bfdf44b..e9f9bd9 100644 --- a/gpslog/models.py +++ b/gpslog/models.py @@ -27,13 +27,9 @@ class GPSPoint(models.Model): token = models.ForeignKey(GPSToken, models.SET_NULL, null=True) # Optional additional information - battery = models.DecimalField( - max_digits=5, decimal_places=2, null=True, blank=True) - accuracy = models.DecimalField( - max_digits=64, decimal_places=32, null=True, blank=True) - speed = models.DecimalField( - max_digits=64, decimal_places=32, null=True, blank=True) - bearing = models.DecimalField( - max_digits=64, decimal_places=61, null=True, blank=True) + battery = models.FloatField(null=True, blank=True) + accuracy = models.FloatField(null=True, blank=True) + speed = models.FloatField(null=True, blank=True) + bearing = models.FloatField(null=True, blank=True) satellites = models.IntegerField(null=True, blank=True) user_agent = models.TextField(null=True, blank=True)