Commit 5bfe901b authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

AdhesionDeletableFilter

parent eb5d46f2
from django.contrib import admin
from django.contrib.auth.models import User as AuthUser
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.db.models import Q
from django.utils.html import format_html
from django.utils import timezone
from django.conf.urls import url
......@@ -114,6 +115,29 @@ class AdhesionImportedFilter(admin.SimpleListFilter):
return queryset.filter(notes="")
class AdhesionDeletableFilter(admin.SimpleListFilter):
title = "supprimable"
parameter_name = "deletable"
def lookups(self, request, model_admin):
return (
("0", "Non"),
("1", "Oui"),
)
def queryset(self, request, queryset):
one_year_ago = timezone.now() - timedelta(days=366)
q = Q(
active=False,
payment_method=PaymentUpdate.STOP,
last_echeance__lte=one_year_ago,
)
if self.value() == "0":
return queryset.filter(q)
if self.value() == "1":
return queryset.exclude(q)
# ## Mixins
......@@ -309,7 +333,12 @@ class AdhesionAdmin(AdtSearchMixin, admin.ModelAdmin):
"is_active",
"last_echeance_display",
)
list_filter = (AdherentTypeFilter, ActiveFilter, AdhesionImportedFilter)
list_filter = (
AdherentTypeFilter,
ActiveFilter,
AdhesionImportedFilter,
AdhesionDeletableFilter,
)
list_select_related = (
"user",
"user__profile",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment