我在使用 django 时间字段时遇到问题。
我的模型:
class IpCameraAlert(models.Model):
ipCamera = models.ForeignKey(IpCamera, verbose_name='Zone')
start = models.TimeField()
end = models.TimeField()
email_to = models.CharField(max_length=255, null=True, blank=True, verbose_name='Email to')
sms_to = models.CharField(max_length=255, null=True, blank=True, verbose_name='SMS to')
created = models.DateTimeField(auto_now_add=True, editable=False)
modified = models.DateTimeField(auto_now=True, editable=False)
user = models.ForeignKey('auth.User', editable=False)
如果我执行以下操作:
timenow = datetime.datetime.time(datetime.datetime.now())
alerts = IpCameraAlert.objects.filter(ipCamera=camera, start__lte=timenow, end__gte=timenow)
我总是得到回应:
ValueError: Can't encode datetime.time(13, 10, 50, 251016)
或类似的取决于时间。它曾经在 1.4 中工作,但由于某种原因它现在不工作了.. 有什么想法吗?