Razmig Sarkissian 4 weeks ago
commit f152a441d4
  1. 3
      sync/models/base.py
  2. 11
      tournaments/admin.py
  3. 6
      tournaments/templates/admin/tournaments/dashboard.html

@ -132,9 +132,8 @@ class BaseModel(models.Model):
children_by_model = self.get_children_by_model() children_by_model = self.get_children_by_model()
for queryset in children_by_model.values(): for queryset in children_by_model.values():
for child in queryset: for child in queryset:
children.append(child)
# Recursively get children of children
if isinstance(child, BaseModel): if isinstance(child, BaseModel):
children.append(child)
children.extend(child.get_recursive_children(processed_objects)) children.extend(child.get_recursive_children(processed_objects))
return children return children

@ -6,7 +6,7 @@ from django.utils.html import escape
from django.urls import reverse, path from django.urls import reverse, path
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.shortcuts import render from django.shortcuts import render
from django.db.models import Avg from django.db.models import Avg, Count
from datetime import timedelta, datetime from datetime import timedelta, datetime
from biz.models import Prospect, ProspectGroup from biz.models import Prospect, ProspectGroup
@ -18,7 +18,6 @@ from .filters import TeamScoreTournamentListFilter, MatchTournamentListFilter, S
from sync.admin import SyncedObjectAdmin from sync.admin import SyncedObjectAdmin
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class CustomUserAdmin(UserAdmin): class CustomUserAdmin(UserAdmin):
@ -241,6 +240,10 @@ class TournamentAdmin(SyncedObjectAdmin):
avg_teams=Avg('tournament__team_count') avg_teams=Avg('tournament__team_count')
)['avg_teams'] or 0 )['avg_teams'] or 0
email_count = PlayerRegistration.objects.aggregate(
total=Count('email', distinct=True)
)['total']
avg_entry_fee = Tournament.objects.exclude(is_deleted=True).aggregate( avg_entry_fee = Tournament.objects.exclude(is_deleted=True).aggregate(
avg_fee=Avg('entry_fee') avg_fee=Avg('entry_fee')
)['avg_fee'] or 0 )['avg_fee'] or 0
@ -325,6 +328,7 @@ class TournamentAdmin(SyncedObjectAdmin):
'tournaments_with_payment': tournaments_with_payment, 'tournaments_with_payment': tournaments_with_payment,
'avg_teams_per_tournament': round(avg_teams_per_tournament, 1), 'avg_teams_per_tournament': round(avg_teams_per_tournament, 1),
'avg_entry_fee': round(avg_entry_fee, 2), 'avg_entry_fee': round(avg_entry_fee, 2),
'email_count': email_count,
# User statistics # User statistics
'total_users': total_users, 'total_users': total_users,
@ -357,12 +361,13 @@ class TeamRegistrationAdmin(SyncedObjectAdmin):
list_display = ['player_names', 'group_stage', 'name', 'tournament', 'registration_date'] list_display = ['player_names', 'group_stage', 'name', 'tournament', 'registration_date']
list_filter = [SimpleTournamentListFilter] list_filter = [SimpleTournamentListFilter]
search_fields = ['id'] search_fields = ['id']
raw_id_fields = ['related_user', 'tournament']
class TeamScoreAdmin(SyncedObjectAdmin): class TeamScoreAdmin(SyncedObjectAdmin):
list_display = ['team_registration', 'score', 'walk_out', 'match'] list_display = ['team_registration', 'score', 'walk_out', 'match']
list_filter = [TeamScoreTournamentListFilter] list_filter = [TeamScoreTournamentListFilter]
search_fields = ['id', 'team_registration__player_registrations__first_name', 'team_registration__player_registrations__last_name'] search_fields = ['id', 'team_registration__player_registrations__first_name', 'team_registration__player_registrations__last_name']
raw_id_fields = ['team_registration', 'match'] # Add this line raw_id_fields = ['team_registration', 'match']
list_per_page = 50 # Controls pagination on the list view list_per_page = 50 # Controls pagination on the list view
def get_queryset(self, request): def get_queryset(self, request):

@ -136,10 +136,14 @@
<div style="font-size: 32px; font-weight: bold;">{{ total_players }}</div> <div style="font-size: 32px; font-weight: bold;">{{ total_players }}</div>
<div style="opacity: 0.9; font-size: 16px;">Total Players</div> <div style="opacity: 0.9; font-size: 16px;">Total Players</div>
</div> </div>
<div> <div style="margin-bottom: 20px;">
<div style="font-size: 20px; font-weight: bold;">{{ avg_teams_per_tournament }}</div> <div style="font-size: 20px; font-weight: bold;">{{ avg_teams_per_tournament }}</div>
<div style="opacity: 0.9; font-size: 14px;">Avg Teams/Tournament</div> <div style="opacity: 0.9; font-size: 14px;">Avg Teams/Tournament</div>
</div> </div>
<div>
<div style="font-size: 20px; font-weight: bold;">{{ email_count }}</div>
<div style="opacity: 0.9; font-size: 14px;">Distinct emails</div>
</div>
</div> </div>
</div> </div>

Loading…
Cancel
Save