-3

我正在尝试使用嵌套 if 做一个项目。但它不起作用。为什么?我的代码是,

schedule = Schedule.objects.all()
    for c in schedule :
        p = c.poll
        e = c.end_time
        s = c.start_time
        n = c.no_of_response
        now = timezone.now()
        #phn = Response.objects.filter(poll = p).exclude(sid = 'Null').count()
        if (c.start_time <= now) & (now <= c.end_time):
            if n == 0:
                c.poll.status='Running'
                c.poll.save()
4

1 回答 1

2

您正在与 进行一些比较&,您可能想要使用and(或&&)

(c.start_time <= now) and (now <= c.end_time)

或者更好

c.start_time <= now <= c.end_time
于 2016-04-15T08:58:31.010 回答