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 %} -