mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
Fix filter by scale counters and add consist constrains
Still to be improved, see FIXME
This commit is contained in:
@@ -551,16 +551,30 @@ class Scales(GetData):
|
||||
item_type = "scale"
|
||||
|
||||
def get_data(self, request):
|
||||
return Scale.objects.annotate(
|
||||
num_items=Count(
|
||||
"rollingstock",
|
||||
filter=Q(
|
||||
rollingstock__in=RollingStock.objects.get_published(
|
||||
request.user
|
||||
)
|
||||
return (
|
||||
Scale.objects.annotate(
|
||||
num_rollingstock=Count(
|
||||
"rollingstock",
|
||||
filter=Q(
|
||||
rollingstock__in=RollingStock.objects.get_published(
|
||||
request.user
|
||||
)
|
||||
),
|
||||
distinct=True,
|
||||
),
|
||||
),
|
||||
).order_by("-ratio_int", "-tracks", "scale")
|
||||
num_consists=Count(
|
||||
"consist",
|
||||
filter=Q(
|
||||
consist__in=Consist.objects.get_published(
|
||||
request.user
|
||||
)
|
||||
),
|
||||
distinct=True,
|
||||
),
|
||||
)
|
||||
.annotate(num_items=F("num_rollingstock") + F("num_consists"))
|
||||
.order_by("-ratio_int", "-tracks", "scale")
|
||||
)
|
||||
|
||||
|
||||
class Types(GetData):
|
||||
|
Reference in New Issue
Block a user