First version of the cable list

This commit is contained in:
2022-02-14 11:49:49 +00:00
parent ccdc13df93
commit c4aafbd7e5
4 changed files with 198 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ from io import BytesIO
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core import serializers
from django.db.models import Q
from django.db.models import Q, Sum
from django.http import Http404, HttpResponse, JsonResponse
from django.urls import reverse, reverse_lazy
from django.utils import timezone
@@ -81,6 +81,24 @@ class AssetList(LoginRequiredMixin, generic.ListView):
return context
class CableList(AssetList):
template_name = 'cable_list.html'
def get_queryset(self):
queryset = super().get_queryset().filter(is_cable=True)
if self.form.cleaned_data['cable_type']:
queryset = queryset.filter(cable_type__in=self.form.cleaned_data['cable_type'])
return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_title"] = "Cable List"
context["total_length"] = self.get_queryset().aggregate(Sum('length'))['length__sum']
return context
class AssetIDUrlMixin:
def get_object(self, queryset=None):
pk = self.kwargs.get(self.pk_url_kwarg)