嵌套如果在django中不起作用

时间:2016-04-15 08:54:24

标签: django django-models django-admin djcelery

我正在尝试使用嵌套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()

1 个答案:

答案 0 :(得分:2)

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

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

或更好

c.start_time <= now <= c.end_time