我的Django应用程序中有以下模型:
class PeopleCount(models.Model):
"""
A webapp model classs to store People Count Details.
"""
timestamp = models.DateTimeField(auto_now=True)
people_count_entry = models.IntegerField(blank=True, null=True)
people_count_exit = models.IntegerField(blank=True, null=True)
store = models.ForeignKey(Store, blank=True, null=True)
profile = models.ForeignKey(Profile)
camera = models.ForeignKey(Camera)
recorded_time = models.DateTimeField(null=True, blank=True)
def __str__(self):
return "People Count {}".format(self.timestamp)
class Meta:
verbose_name = "People Count"
verbose_name_plural = "People Count"
ordering = ['-recorded_time']
我想打印出PeopleCount的值,如果两个对象的登记时间之间的差异小于1秒,我可以聚合它们的值。例如:
我尝试使用聚合查询,但无法输入过滤器的差值为1秒。
希望我对这个问题很清楚。 TIA
AFAIK,您无法执行此操作,因为Django不提供对查询集的组合检查/注释。
从逻辑上讲,你试图比较彼此的对象,可能有nC2
组合(如果你有100个对象,你需要检查4950组合,100C2=4950
),这是无法通过数据库/ django orm完成的