我有这个查询集函数来计算字段created
,但我想按天计算,而不是现在的情况,因为我想用这些数据制作图表。
queryset = Model.objects.filter(
user=user
).values("created").annotate(
Count("created")).order_by("created")
结果:
[{"created__count": 1, "created": "2013-10-01T09:05:50Z"}, {"created__count": 1, "created": "2013-10-01T09:05:53Z"}, {"created__count": 1, "created": "2013-10-01T09:05:56Z"}, {"created__count": 1, "created": "2013-10-01T09:26:37Z"}, {"created__count": 1, "created": "2013-10-01T09:26:41Z"}, {"created__count": 1, "created": "2013-10-01T09:27:10Z"}, {"created__count": 1, "created": "2013-10-01T09:27:15Z"}, {"created__count": 1, "created": "2013-10-01T10:12:40Z"}, {"created__count": 1, "created": "2013-10-01T10:12:46Z"}, {"created__count": 1, "created": "2013-10-01T10:12:53Z"}]
这有一些方法可以按天计算,例如 11/11:Count 20、12/11:Count 22。
我应该在从查询集中获得这些数据后计算它吗?