这段代码一直给我错误。我的 Django 模型中有一个字段(日期时间),invite_sent
同一个模型中的另一个字段称为check_time
Check time 是invite sent
应该发生某个操作之后的时间量。出于某种原因,我的代码无法正常工作。
模型.py
class Game(models.Model):
title = models.CharField(max_length=50)
summery = models.CharField(max_length=500)
pin = models.CharField(max_length=12)
key = models.CharField(max_length=12)
complete = models.BooleanField()
invite_sent = models.DateTimeField() #<-----------
check_time = models.IntegerField() #<-----------
on = models.ForeignKey("Member", related_name="turn", blank=True, null=True)
视图.py
def check_time():
games = Game.objects.filter(complete = False)
for g in games:
hours = (datetime.datetime - g.invite_sent)/60/60 # trying to get hours between now and then
if not hours > g.check_time: #stuff beyond this is not really important to the issue
continue
send_overtime(g)
set_on(g)
send_invite(g)