我已经编写了一些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出发的3辆下一班车,并通过arrival_time到达to_stop。
我想在from_stop和to_stop之间返回TimingLinks,每个运行时连续添加到VehicleJourney.departure_time,给出每个站点的出发时间。
关于我如何最好地接近这个的任何见解?