diff --git a/apps/counter/api/views.py b/apps/counter/api/views.py index f2ae239..ea8d2b8 100644 --- a/apps/counter/api/views.py +++ b/apps/counter/api/views.py @@ -61,7 +61,8 @@ class DeviceLogStatisticAPIView(APIView): def get(self, request, *args, **kwargs): # calc total count, no cache - total_count_queryset = [DeviceCount.objects.get(device_id=x['device_id'], data_time=x['max_time']) + total_count_queryset = [DeviceCount.objects.filter(device_id=x['device_id'], + data_time=x['max_time']).order_by('-count')[0] for x in DeviceCount.objects.values('device_id').annotate(max_time=Max('data_time'))] if total_count_queryset: total_count = sum(map(lambda x: int(x.count), total_count_queryset))