我已经编写了一些 Django 模型并为公交车时刻表系统加载了一些数据,但是在编写查询时遇到了麻烦。以下是模型:
class VehicleJourney(models.Model):
vehicle_journey = models.CharField(primary_key=True, max_length=100)
journey_pattern = models.ForeignKey('JourneyPattern')
departure_time = models.TimeField()
class TimingLink(models.Model):
timing_link = models.CharField(primary_key=True, max_length=100)
journey_pattern = models.ForeignKey('JourneyPattern')
from_seq_no = models.IntegerField()
from_stop = models.ForeignKey('Stop', related_name='+')
to_seq_no = models.IntegerField()
to_stop = models.ForeignKey('Stop', related_name='+')
runtime = models.IntegerField()
class Stop(models.Model):
stop_point = models.CharField(primary_key=True, max_length=100)
common_name = models.CharField(max_length=250)
class JourneyPattern(models.Model):
journey_pattern = models.CharField(primary_key=True, max_length=100)
direction = models.CharField(max_length=100)
service = models.ForeignKey('Service')
class Service(models.Model):
service_code = models.CharField(primary_key=True, max_length=100)
registered_operator_ref = models.ForeignKey('Operator')
mode = models.CharField(max_length=100)
description = models.CharField(max_length=250)
start_date = models.DateField()
end_date = models.DateField()
origin = models.CharField(max_length=250)
destination = models.CharField(max_length=250)
该查询输入 from_stop、to_stop 和到达时间,以查找从 from_stop 出发并在到达时间到达 to_stop 的 3 辆下一辆公共汽车。
我想返回 from_stop 和 to_stop 之间的 TimingLinks,每个运行时依次添加到 VehicleJourney.departure_time 中,给出每个站点的出发时间。
关于如何最好地解决这个问题的任何见解?