Skip to content

Commit

Permalink
relais admin: filter owners without vehicules
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Mar 29, 2024
1 parent 4a300f4 commit 8937eb2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mesads/vehicules_relais/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class VehiculeCount(admin.SimpleListFilter):

def lookups(self, request, model_admin):
return (
("0", "Aucun véhicule"),
("1", ">=1 véhicule"),
("5", ">=5 véhicules"),
("10", ">=10 véhicules"),
Expand All @@ -33,7 +34,10 @@ def queryset(self, request, queryset):
return queryset

queryset = queryset.annotate(vehicule_count=Count("vehicule"))
return queryset.filter(vehicule_count__gte=count_filter)
if count_filter == 0:
return queryset.filter(vehicule_count=count_filter)
else:
return queryset.filter(vehicule_count__gte=count_filter)


@admin.register(Proprietaire)
Expand Down

0 comments on commit 8937eb2

Please sign in to comment.