From 5bf873f2823a448ec36668e029fdaba7f7706ba4 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Mon, 3 Mar 2025 13:08:52 -0300 Subject: [PATCH] add collapse and search function --- lot/forms.py | 13 ++- lot/templates/list_lots.html | 184 +++++++++++++++++++++++++++++------ 2 files changed, 167 insertions(+), 30 deletions(-) diff --git a/lot/forms.py b/lot/forms.py index cc396f1..c60abd6 100644 --- a/lot/forms.py +++ b/lot/forms.py @@ -4,10 +4,21 @@ from lot.models import Lot class LotsForm(forms.Form): lots = forms.ModelMultipleChoiceField( - queryset=Lot.objects.all(), + queryset=Lot.objects.filter(archived=False), widget=forms.CheckboxSelectMultiple, ) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + #grouping lots by their lot group for more readability + self.grouped_lots = {} + for lot in self.fields['lots'].queryset: + group_name = lot.type.name if lot.type else "No group" + if group_name not in self.grouped_lots: + self.grouped_lots[group_name] = [] + self.grouped_lots[group_name].append(lot) + def clean(self): self._lots = self.cleaned_data.get("lots") return self._lots diff --git a/lot/templates/list_lots.html b/lot/templates/list_lots.html index 50caf8b..f79dbd3 100644 --- a/lot/templates/list_lots.html +++ b/lot/templates/list_lots.html @@ -2,37 +2,163 @@ {% load i18n %} {% block content %} -
-
-

{{ subtitle }}

+ + + +
+
+

{{ subtitle }}

+
-
- -
- {% csrf_token %} - - - - - - - - - - {% for tag in lot_tags %} - {% for lot in lots %} - {% if lot.type == tag %} - - - - - {% endif %} +
+ +
+ + {% csrf_token %} + {% for group_name, lots in form.grouped_lots.items %} +
+ +
+
+ {% for lot in lots %} +
+ + +
+ {% endfor %} +
+
+
{% endfor %} - {% endfor %} - -
SelectLot Group / Lot
{{ tag }}/{{ lot.name }}
+ +
- - + {% endblock %}