我的字段在我的django应用程序live_from
和live_to
这些字段是不需要的。TypeError:无法订购的类型:无类型()<= datetime.datetime()
字段:当此字段为空,我在梅托德得到一个错误
live_from = models.DateTimeField('live from', blank=True, null=True)
live_to = models.DateTimeField('live to', blank=True, null=True)
这里是我的方法:
def is_live(self):
return (self.live_from <= timezone.now()) and (self.live_to >= timezone.now())
错误:TypeError: unorderable types: NoneType() <= datetime.datetime()
看起来不像编码错误,更像是设计错误。如果这些字段是空的,'is_live'应该做什么? – TigerhawkT3
因此,无论是'live_from'还是'live_to'都是None,因为您允许使用空值。 'life_from'这个例外看起来是'None',但这同样适用于'live_to'。如果其中任何一个都是空的,会发生什么? –