34 lines
941 B
Python
34 lines
941 B
Python
|
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"]]
|
||
|
|