Сокрытие пустых веток
This commit is contained in:
parent
e8b64f5cbb
commit
9ebe51fdfd
@ -5,6 +5,8 @@ import io
|
||||
import json
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from django.db.models import Count, Prefetch
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.conf import settings
|
||||
@ -109,12 +111,26 @@ def monitoring_add(request):
|
||||
def monitoring_list(request):
|
||||
try:
|
||||
param=request.GET.dict()
|
||||
catalog_list=ObStation.objects.prefetch_related('point_set').order_by("name")
|
||||
# Аннотация количества связанных PointIndicators
|
||||
catalog_list = ObStation.objects.annotate(
|
||||
indicators_count=Count('point__pointindicators', distinct=True)
|
||||
# Подсчет индикаторов через цепочку
|
||||
).filter(
|
||||
indicators_count__gt=0 # Оставляем только станции с индикаторами
|
||||
).prefetch_related(
|
||||
Prefetch('point_set', queryset=Point.objects.prefetch_related(
|
||||
'pointindicators_set'))
|
||||
).order_by("name")
|
||||
|
||||
# Дополнительная обработка
|
||||
for catalog in catalog_list:
|
||||
catalog.sorted_points = sorted(catalog.point_set.all(),
|
||||
key=lambda point: natural_sort_key(point.name))
|
||||
catalog.sorted_points = sorted(
|
||||
catalog.point_set.all(),
|
||||
key=lambda point: natural_sort_key(point.name)
|
||||
)
|
||||
for point in catalog.sorted_points:
|
||||
point.monitoring = point.pointindicators_set.all().order_by("point")
|
||||
point.monitoring = point.pointindicators_set.all().order_by(
|
||||
"point")
|
||||
catalog_count = catalog_list.count()
|
||||
paginator = Paginator(catalog_list, 50)
|
||||
page_number = request.GET.get('page',1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user