我有这个模型:
class TimeInterval(models.Model):
startTime = models.DateTimeField()
endTime = models.DateTimeField()
如何仅使用 QuerySet API 聚合平均时间间隔?
我试过这个:
qs = TimeInterval.objects.extra(
select={"duration": "endTime - startTime"}).aggregate(
Avg("duration"))
但它抛出:
FieldError: Cannot resolve keyword 'duration' into field. Choices are:
endTime, startTime