Skip to content

Commit 90e774f

Browse files
author
Dmytro Trotsko
committed
Fixed stats
1 parent 9d1b7f8 commit 90e774f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/indicatorsets/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class IndicatorSetFilter(django_filters.FilterSet):
2424

25-
indicators_qs = Indicator.objects.filter(indicator_set__isnull=False)
25+
indicators_qs = Indicator.objects.filter(indicator_set__isnull=False).select_related("indicator_set", "source")
2626

2727
pathogens = django_filters.ModelMultipleChoiceFilter(
2828
field_name="pathogens",

src/indicatorsets/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ def get_table_stats_info(request):
641641
queryset = IndicatorSet.objects.none()
642642

643643
filter = IndicatorSetFilter(request.GET, queryset=queryset)
644-
num_locations = get_num_locations_from_meta(filter.indicators_qs.values("source__name", "name").distinct())
645-
return JsonResponse({"num_of_indicator_sets": filter.qs.count(), "num_of_indicators": filter.indicators_qs.count(), "num_of_locations": num_locations})
644+
related_indicators = filter.indicators_qs.filter(indicator_set__id__in=filter.qs.values_list("id", flat=True))
645+
num_locations = get_num_locations_from_meta(related_indicators.values("source__name", "name").distinct())
646+
return JsonResponse({"num_of_indicator_sets": filter.qs.count(), "num_of_indicators": related_indicators.count(), "num_of_locations": num_locations})
646647

647648

648649
def get_related_indicators_json(request):

0 commit comments

Comments
 (0)