models.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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=3)
  7. hdop = models.IntegerField(null=True, blank=True)
  8. speed = models.IntegerField(null=True, blank=True)
  9. class Trip(models.Model):
  10. startTime = models.DateTimeField()
  11. endTime = models.DateTimeField()
  12. name = models.CharField(max_length=255)
  13. description = models.TextField(null=True, blank=True)
  14. class CensoredLocation(models.Model):
  15. location = PointField(dim=2)
  16. radius = models.IntegerField(default=800)
  17. name = models.CharField(max_length=255)
  18. def delete_markers(self, markers = None) -> int:
  19. # matches = Marker.objects.filter(location__distance_lt=(
  20. # self.location,
  21. # Distance(m=self.radius)
  22. # ))
  23. matches = Marker.objects.annotate(distance=Distance('location', self.location)
  24. ).filter(distance__lte=self.radius)
  25. count = len(matches)
  26. matches.delete()
  27. return count