@property
def total_duration_of_videos(self):
videos_qs = self.videos.all()
total_duration = datetime.timedelta(0,0,0)
for video in videos_qs:
total_duration += video.total_time
hours, remainder = divmod(total_duration.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return str(hours)+":"+str(minutes)+":"+str(seconds)
这就是我在这里写的内容,我并非无法找到解决方案。
对于某些video
人来说videos_qs
,video.total_time
正在回归None
。这就是为什么您得到错误。
要解决此错误改变total_duration += video.total_time
线路total_duration += (video.total_time or datetime.timedelta(0,0,0))
如下。
@property
def total_duration_of_videos(self):
videos_qs = self.videos.all()
total_duration = datetime.timedelta(0,0,0)
for video in videos_qs:
otal_duration += (video.total_time or datetime.timedelta(0,0,0))
hours, remainder = divmod(total_duration.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return str(hours)+":"+str(minutes)+":"+str(seconds)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句