2
我有一个关于fieldmeasurement的字段'startDate'类型为datetime的元数据表。当没有信息可用时,该值可以为空。我想在此字段上运行一些统计数据,并获取最小值和最大值(即所有记录中可用的最早测量值)。 Max没有问题,但对于Min,聚合返回None(空字段中的值)。django过滤日期时间=无
所以我的想法是在运行聚合之前从查询集中过滤这些记录。我找不到如何做到这一点。
我已经试过
oldestdate = Measurement.object.filter(startDate__isNull=True).aggregate(Min('startDate'))['startDate__min']
任何想法是错的,或者如何做到这一点?
编辑: 一些更多的测试表明:
Measurement.objects.filter(startDate_isnull=True) -> only records with startDate = None
Measurement.objects.filter(startDate_isnull=False) -> all records, also the ones with startDate = None.
Measurement.objects.exclude(startDate__isnull=False) -> only records with startDate = None
Measurement.objects.exclude(startDate__isnull=True) -> shows all records (also startDate == None)
你曾经工作过的节点socketio和Django的 – masterofdestiny 2013-03-06 12:44:43
它不工作。带有None的字段不会被过滤掉。 oQuery = WindWaveFile.objects.all()oQuery.exclude(startDate__isnull = True).aggregate(Min('startDate'))['startDate__min']。strftime(“%d /%m /%Y%H:%M” )。 strftime引发了一个异常,因为(错误'NoneType'对象没有属性'strftime') – 2013-03-11 12:07:08
正确,在我之前发布的版本中,尚未添加strftime部分。但是,原始问题依然存在,过滤器无法识别无。 – 2013-03-11 12:16:38