from django.contrib import admin from .models import Club, TeamScore, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamRegistration, PlayerRegistration, Purchase, Court, DateInterval, FailedApiCall from django.db.models import Q from django.utils.translation import gettext_lazy as _ import uuid class TeamScoreTournamentListFilter(admin.SimpleListFilter): # Human-readable title which will be displayed in the # right admin sidebar just above the filter options. title = _("tournoi") # Parameter for the filter that will be used in the URL query. parameter_name = "tournament" def lookups(self, request, model_admin): tournaments = Tournament.objects.order_by('-start_date') return [(t.id, t.filter_name()) for t in tournaments] def queryset(self, request, queryset): if self.value(): return queryset.filter(team_registration__tournament__id=self.value()) else: return queryset class MatchTournamentListFilter(admin.SimpleListFilter): # Human-readable title which will be displayed in the # right admin sidebar just above the filter options. title = _("tournoi") # Parameter for the filter that will be used in the URL query. parameter_name = "tournament" def lookups(self, request, model_admin): tournaments = Tournament.objects.order_by('-start_date') return [(t.id, t.filter_name()) for t in tournaments] def queryset(self, request, queryset): if self.value(): query_round = Q(round__tournament__id=self.value()) query_group_stage = Q(group_stage__tournament__id=self.value()) return queryset.filter(query_round | query_group_stage) else: return queryset