我在models.py中尝试了两次减法,但都出错了。这是我一直在工作的模型
class Schedule(BaseModel):
bus_company_route = models.ForeignKey(BusCompanyRoute, on_delete=models.PROTECT)
travel_date_time = models.DateTimeField()
和BusCompanyRoute
有行程长度
class BusCompanyRoute(BaseModel):
journey_length = models.TimeField(null=True)
现在,我尝试使用@property
decorator以以下方式添加这些时间
@property
def journey_end_time(self):
return self.travel_date_time.time()+self.bus_company_route.journey_length
但最终得到以下错误警告:
Class 'time' does not define '__add__', so the '+' operator cannot be used on its instances
我怎样才能解决它
^{} 更适合存储旅程的持续时间,而不是
TimeField
,这将为您提供一个时间增量,您可以从日期时间中添加或减去,而TimeField
只提供一天中的静态时间相关问题 更多 >
编程相关推荐