Skip to content

Commit

Permalink
admin relais: filter deleted at vehicules
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Feb 2, 2025
1 parent 05fa9ce commit 060590f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mesads/vehicules_relais/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ def vehicules_link(self, obj):
return mark_safe(f'<a href="{url}">Voir les {obj.vehicule_count} véhicules</a>')


class VehiculeDeletedAtFilter(admin.SimpleListFilter):
title = "Filtrer les véhicules supprimés"
parameter_name = "deleted_at" # URL query parameter

def lookups(self, request, model_admin):
return (
("deleted", "Supprimés"),
("active", "Actifs"),
)

def queryset(self, request, queryset):
if self.value() == "deleted":
return queryset.exclude(deleted_at__isnull=True)
if self.value() == "active":
return queryset.filter(deleted_at__isnull=True)
return queryset


@admin.register(Vehicule)
class VehiculeAdmin(admin.ModelAdmin):
def get_queryset(self, request):
Expand Down Expand Up @@ -172,7 +190,7 @@ def get_queryset(self, request):
"commune_localisation",
)

list_filter = ("departement",)
list_filter = ("departement", VehiculeDeletedAtFilter)


@admin.register(DispositionSpecifique)
Expand Down

0 comments on commit 060590f

Please sign in to comment.