Update admin.py

sync3
Razmig Sarkissian 5 months ago
parent d541205f22
commit 621639f30e
  1. 96
      tournaments/admin.py

@ -107,10 +107,51 @@ class TournamentAdmin(SyncedObjectAdmin):
tournaments_today_public = tournaments_today.filter(is_private=False).count()
tournaments_today_total = tournaments_today.count()
# Tournament statistics - running this week
tournaments_this_week = Tournament.objects.filter(
Q(start_date__date__gte=week_ago) |
Q(end_date__date__gte=week_ago, start_date__date__lte=today)
).exclude(is_deleted=True)
tournaments_week_private = tournaments_this_week.filter(is_private=True).count()
tournaments_week_public = tournaments_this_week.filter(is_private=False).count()
tournaments_week_total = tournaments_this_week.count()
# Tournament statistics - running this month
tournaments_this_month = Tournament.objects.filter(
Q(start_date__date__gte=month_ago) |
Q(end_date__date__gte=month_ago, start_date__date__lte=today)
).exclude(is_deleted=True)
tournaments_month_private = tournaments_this_month.filter(is_private=True).count()
tournaments_month_public = tournaments_this_month.filter(is_private=False).count()
tournaments_month_total = tournaments_this_month.count()
# All time tournament statistics
all_tournaments = Tournament.objects.exclude(is_deleted=True)
tournaments_all_private = all_tournaments.filter(is_private=True).count()
tournaments_all_public = all_tournaments.filter(is_private=False).count()
tournaments_all_total = all_tournaments.count()
# Ended tournaments
tournaments_ended_today = Tournament.objects.filter(
end_date__date=today
).exclude(is_deleted=True)
tournaments_ended_week = Tournament.objects.filter(
end_date__date__gte=week_ago,
end_date__date__lte=today
).exclude(is_deleted=True)
tournaments_ended_month = Tournament.objects.filter(
end_date__date__gte=month_ago,
end_date__date__lte=today
).exclude(is_deleted=True)
tournaments_ended_all = Tournament.objects.filter(
end_date__lt=now
).exclude(is_deleted=True)
# Team and player statistics
total_teams = TeamRegistration.objects.count()
total_players = PlayerRegistration.objects.count()
@ -118,16 +159,71 @@ class TournamentAdmin(SyncedObjectAdmin):
# Match statistics
total_matches = Match.objects.count()
matches_played = Match.objects.filter(end_date__isnull=False).count()
matches_pending = Match.objects.filter(end_date__isnull=True).count()
# Additional statistics
tournaments_with_online_reg = Tournament.objects.filter(
enable_online_registration=True
).exclude(is_deleted=True).count()
tournaments_with_payment = Tournament.objects.filter(
enable_online_payment=True
).exclude(is_deleted=True).count()
# Average statistics
avg_teams_per_tournament = TeamRegistration.objects.aggregate(
avg_teams=Avg('tournament__team_count')
)['avg_teams'] or 0
avg_entry_fee = Tournament.objects.exclude(is_deleted=True).aggregate(
avg_fee=Avg('entry_fee')
)['avg_fee'] or 0
context = {
'title': 'Tournament Dashboard',
'app_label': 'tournaments',
'opts': Tournament._meta,
# Today statistics
'tournaments_today_total': tournaments_today_total,
'tournaments_today_private': tournaments_today_private,
'tournaments_today_public': tournaments_today_public,
# Week statistics
'tournaments_week_total': tournaments_week_total,
'tournaments_week_private': tournaments_week_private,
'tournaments_week_public': tournaments_week_public,
# Month statistics
'tournaments_month_total': tournaments_month_total,
'tournaments_month_private': tournaments_month_private,
'tournaments_month_public': tournaments_month_public,
# All time statistics
'tournaments_all_total': tournaments_all_total,
'tournaments_all_private': tournaments_all_private,
'tournaments_all_public': tournaments_all_public,
# Ended tournaments
'tournaments_ended_today': tournaments_ended_today.count(),
'tournaments_ended_week': tournaments_ended_week.count(),
'tournaments_ended_month': tournaments_ended_month.count(),
'tournaments_ended_all': tournaments_ended_all.count(),
# Teams and players
'total_teams': total_teams,
'total_players': total_players,
# Matches
'total_matches': total_matches,
'matches_played': matches_played,
'matches_pending': matches_pending,
# Additional stats
'tournaments_with_online_reg': tournaments_with_online_reg,
'tournaments_with_payment': tournaments_with_payment,
'avg_teams_per_tournament': round(avg_teams_per_tournament, 1),
'avg_entry_fee': round(avg_entry_fee, 2),
}
return render(request, 'admin/tournaments/dashboard.html', context)

Loading…
Cancel
Save