mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Fix another counting issue
This commit is contained in:
@@ -491,10 +491,37 @@ class Manufacturers(GetData):
|
|||||||
|
|
||||||
def get_data(self, request):
|
def get_data(self, request):
|
||||||
return (
|
return (
|
||||||
Manufacturer.objects.filter(self.filter)
|
Manufacturer.objects.filter(self.filter).annotate(
|
||||||
.annotate(
|
num_rollingstock=(
|
||||||
num_items=Count("rollingstock") + Count("rollingclass"),
|
Count(
|
||||||
|
"rollingstock",
|
||||||
|
filter=Q(
|
||||||
|
rollingstock__in=(
|
||||||
|
RollingStock.objects.get_published(
|
||||||
|
request.user
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
distinct=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
.annotate(
|
||||||
|
num_rollingclass=(
|
||||||
|
Count(
|
||||||
|
"rollingclass__rolling_class",
|
||||||
|
filter=Q(
|
||||||
|
rollingclass__rolling_class__in=(
|
||||||
|
RollingStock.objects.get_published(
|
||||||
|
request.user
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
distinct=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.annotate(num_items=F("num_rollingstock") + F("num_rollingclass"))
|
||||||
.order_by("name")
|
.order_by("name")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user