models.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from django.db import models
  2. from django.contrib.gis.db.models.fields import PointField
  3. from django.contrib.gis.db.models.functions import Distance
  4. class Marker(models.Model):
  5. timestamp = models.DateTimeField(unique=True)
  6. location = PointField(dim=2)
  7. alt = models.FloatField("Altitude")
  8. hdop = models.IntegerField(null=True, blank=True)
  9. speed = models.IntegerField(null=True, blank=True)
  10. class Trip(models.Model):
  11. startTime = models.DateTimeField()
  12. endTime = models.DateTimeField()
  13. name = models.CharField(max_length=255)
  14. description = models.TextField(null=True, blank=True)
  15. class CensoredLocation(models.Model):
  16. location = PointField(dim=2)
  17. radius = models.IntegerField(default=800)
  18. name = models.CharField(max_length=255)
  19. def delete_markers(self, markers = None) -> int:
  20. # matches = Marker.objects.filter(location__distance_lt=(
  21. # self.location,
  22. # Distance(m=self.radius)
  23. # ))
  24. matches = Marker.objects.annotate(distance=Distance('location', self.location)
  25. ).filter(distance__lte=self.radius)
  26. count = len(matches)
  27. matches.delete()
  28. return count