diff --git a/sync/models/base.py b/sync/models/base.py index cafbf24..3ac7535 100644 --- a/sync/models/base.py +++ b/sync/models/base.py @@ -132,9 +132,8 @@ class BaseModel(models.Model): children_by_model = self.get_children_by_model() for queryset in children_by_model.values(): for child in queryset: - children.append(child) - # Recursively get children of children if isinstance(child, BaseModel): + children.append(child) children.extend(child.get_recursive_children(processed_objects)) return children diff --git a/tournaments/admin.py b/tournaments/admin.py index 4d1a3f6..c7511c8 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -6,7 +6,7 @@ from django.utils.html import escape from django.urls import reverse, path from django.utils.safestring import mark_safe from django.shortcuts import render -from django.db.models import Avg +from django.db.models import Avg, Count from datetime import timedelta, datetime from biz.models import Prospect, ProspectGroup @@ -18,7 +18,6 @@ from .filters import TeamScoreTournamentListFilter, MatchTournamentListFilter, S from sync.admin import SyncedObjectAdmin import logging - logger = logging.getLogger(__name__) class CustomUserAdmin(UserAdmin): @@ -241,6 +240,10 @@ class TournamentAdmin(SyncedObjectAdmin): avg_teams=Avg('tournament__team_count') )['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_fee=Avg('entry_fee') )['avg_fee'] or 0 @@ -325,6 +328,7 @@ class TournamentAdmin(SyncedObjectAdmin): 'tournaments_with_payment': tournaments_with_payment, 'avg_teams_per_tournament': round(avg_teams_per_tournament, 1), 'avg_entry_fee': round(avg_entry_fee, 2), + 'email_count': email_count, # User statistics 'total_users': total_users, @@ -357,12 +361,13 @@ class TeamRegistrationAdmin(SyncedObjectAdmin): list_display = ['player_names', 'group_stage', 'name', 'tournament', 'registration_date'] list_filter = [SimpleTournamentListFilter] search_fields = ['id'] + raw_id_fields = ['related_user', 'tournament'] class TeamScoreAdmin(SyncedObjectAdmin): list_display = ['team_registration', 'score', 'walk_out', 'match'] list_filter = [TeamScoreTournamentListFilter] 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 def get_queryset(self, request): diff --git a/tournaments/templates/admin/tournaments/dashboard.html b/tournaments/templates/admin/tournaments/dashboard.html index d053c74..5c944ad 100644 --- a/tournaments/templates/admin/tournaments/dashboard.html +++ b/tournaments/templates/admin/tournaments/dashboard.html @@ -136,10 +136,14 @@