From 2d00436a877371f862ec4166a23424c61c847af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Mon, 23 Dec 2024 01:50:58 +0100 Subject: [PATCH] Disable scales if no items are available --- ram/portal/templates/cards/scale.html | 2 +- ram/portal/views.py | 6 ++++-- ram/ram/__init__.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ram/portal/templates/cards/scale.html b/ram/portal/templates/cards/scale.html index c2d8351..b80f1f2 100644 --- a/ram/portal/templates/cards/scale.html +++ b/ram/portal/templates/cards/scale.html @@ -28,7 +28,7 @@
- Show all rolling stock + Show all rolling stock {% if request.user.is_staff %}Edit{% endif %}
diff --git a/ram/portal/views.py b/ram/portal/views.py index 90594c1..b5f7393 100644 --- a/ram/portal/views.py +++ b/ram/portal/views.py @@ -7,7 +7,7 @@ from django.views import View from django.http import Http404, HttpResponseBadRequest from django.db.utils import OperationalError, ProgrammingError -from django.db.models import Q +from django.db.models import Q, Count from django.shortcuts import render, get_object_or_404, get_list_or_404 from django.core.exceptions import ObjectDoesNotExist from django.core.paginator import Paginator @@ -507,7 +507,9 @@ class Scales(GetData): queryset = Scale.objects.all() def get_data(self, request): - return Scale.objects.all() + return Scale.objects.annotate( + num_items=Count("rollingstock") + ) # .filter(num_items__gt=0) to filter data with no items class Types(GetData): diff --git a/ram/ram/__init__.py b/ram/ram/__init__.py index 07f10a7..db52b91 100644 --- a/ram/ram/__init__.py +++ b/ram/ram/__init__.py @@ -1,4 +1,4 @@ from ram.utils import git_suffix -__version__ = "0.14.1" +__version__ = "0.14.2" __version__ += git_suffix(__file__)