Skip to content

Commit

Permalink
Disable scales if no items are available
Browse files Browse the repository at this point in the history
  • Loading branch information
daniviga committed Dec 23, 2024
1 parent 6ff5450 commit 2d00436
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ram/portal/templates/cards/scale.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</tbody>
</table>
<div class="d-grid gap-2 mb-1 d-md-block">
<a class="btn btn-sm btn-outline-primary" href="{% url 'filtered' _filter="scale" search=d.item.slug %}">Show all rolling stock</a>
<a class="btn btn-sm btn-outline-primary{% if d.item.num_items == 0 %} disabled{% endif %}" href="{% url 'filtered' _filter="scale" search=d.item.slug %}">Show all rolling stock</a>
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:metadata_scale_change' d.item.pk %}">Edit</a>{% endif %}
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions ram/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ram/ram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ram.utils import git_suffix

__version__ = "0.14.1"
__version__ = "0.14.2"
__version__ += git_suffix(__file__)

0 comments on commit 2d00436

Please sign in to comment.