swbus/collector/models.py

34 lines
941 B
Python
Raw Permalink Normal View History

2020-04-25 16:32:32 +00:00
from django.contrib.gis.db.models import Model, CharField, TextField, ForeignKey, DateTimeField, PointField, CASCADE
# Create your models here.
class Bus(Model):
id = CharField(max_length=255, primary_key=True)
class Status(Model):
bus = ForeignKey(Bus, on_delete=CASCADE)
timestamp = DateTimeField()
class Meta:
unique_together = [["bus", "timestamp"]]
class StatusKey(Model):
key = CharField(max_length=255, primary_key=True)
class StatusValue(Model):
key = ForeignKey(StatusKey, on_delete=CASCADE)
status = ForeignKey(Status, on_delete=CASCADE)
value = CharField(max_length=255)
class Meta:
unique_together = [["key", "status"]]
class Location(Model):
bus = ForeignKey(Bus, on_delete=CASCADE)
status = ForeignKey(Status, on_delete=CASCADE)
timestamp = DateTimeField()
location = PointField()
class Meta:
unique_together = [["bus", "timestamp"]]