diff --git a/tournaments/admin.py b/tournaments/admin.py
index 2779dfb..006ca06 100644
--- a/tournaments/admin.py
+++ b/tournaments/admin.py
@@ -179,6 +179,41 @@ class TournamentAdmin(SyncedObjectAdmin):
avg_fee=Avg('entry_fee')
)['avg_fee'] or 0
+ # User Account Statistics
+ total_users = CustomUser.objects.count()
+ users_admin = CustomUser.objects.filter(origin=0).count() # ADMIN
+ users_site = CustomUser.objects.filter(origin=1).count() # SITE
+ users_app = CustomUser.objects.filter(origin=2).count() # APP
+
+ # Recent User Registrations
+ recent_users = CustomUser.objects.all().order_by('-date_joined')[:10]
+
+ # New users by period
+ users_today = CustomUser.objects.filter(date_joined__date=today).count()
+ users_this_week = CustomUser.objects.filter(
+ date_joined__date__gte=week_start,
+ date_joined__date__lte=week_end
+ ).count()
+ users_this_month = CustomUser.objects.filter(
+ date_joined__date__gte=month_start,
+ date_joined__date__lte=today + timedelta(days=31 - today.day)
+ ).count()
+
+ # Purchase Statistics
+ total_purchases = Purchase.objects.count()
+ recent_purchases = Purchase.objects.all().order_by('-purchase_date')[:10]
+
+ # Purchases by period
+ purchases_today = Purchase.objects.filter(purchase_date__date=today).count()
+ purchases_this_week = Purchase.objects.filter(
+ purchase_date__date__gte=week_start,
+ purchase_date__date__lte=week_end
+ ).count()
+ purchases_this_month = Purchase.objects.filter(
+ purchase_date__date__gte=month_start,
+ purchase_date__date__lte=today + timedelta(days=31 - today.day)
+ ).count()
+
context = {
'title': 'Tournament Dashboard',
'app_label': 'tournaments',
@@ -224,6 +259,23 @@ 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),
+
+ # User statistics
+ 'total_users': total_users,
+ 'users_admin': users_admin,
+ 'users_site': users_site,
+ 'users_app': users_app,
+ 'users_today': users_today,
+ 'users_this_week': users_this_week,
+ 'users_this_month': users_this_month,
+ 'recent_users': recent_users,
+
+ # Purchase statistics
+ 'total_purchases': total_purchases,
+ 'recent_purchases': recent_purchases,
+ 'purchases_today': purchases_today,
+ 'purchases_this_week': purchases_this_week,
+ 'purchases_this_month': purchases_this_month,
}
return render(request, 'admin/tournaments/dashboard.html', context)
diff --git a/tournaments/templates/admin/tournaments/dashboard.html b/tournaments/templates/admin/tournaments/dashboard.html
index e1269b3..3986625 100644
--- a/tournaments/templates/admin/tournaments/dashboard.html
+++ b/tournaments/templates/admin/tournaments/dashboard.html
@@ -21,7 +21,7 @@
- 🎾 Running Tournaments
+ 🎾 Starting Tournaments
+
+
+
+ 👤 User Statistics
+
+
+
+
+
Total Users: {{ total_users }}
+
+ Admin:
+ {{ users_admin }}
+
+
+ Site:
+ {{ users_site }}
+
+
+ App:
+ {{ users_app }}
+
+
+
+ {% if total_users > 0 %}
+
+
+
+ {% endif %}
+
+
+ Admin
+ Site
+ App
+
+
+
+
+
+
+
New Registrations
+
+
Today:
+
{{ users_today }}
+
+
+
This Week:
+
{{ users_this_week }}
+
+
+
This Month:
+
{{ users_this_month }}
+
+
+
+
+
+
Recently Registered Users
+
+
+
+
+ | Name |
+ Email |
+ Origin |
+ Date Joined |
+
+
+
+ {% for user in recent_users %}
+
+ | {{ user.first_name }} {{ user.last_name }} |
+ {{ user.email }} |
+
+ {% if user.origin == 0 %}
+ Admin
+ {% elif user.origin == 1 %}
+ Site
+ {% elif user.origin == 2 %}
+ App
+ {% else %}
+ Unknown
+ {% endif %}
+ |
+ {{ user.date_joined|date:"M d, Y H:i" }} |
+
+ {% empty %}
+
+ | No recent users found. |
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+
+ 💰 Purchase Statistics
+
+
+
+
+
Total Purchases: {{ total_purchases }}
+
+
Today:
+
{{ purchases_today }}
+
+
+
This Week:
+
{{ purchases_this_week }}
+
+
+
This Month:
+
{{ purchases_this_month }}
+
+
+
+
+
+
Recent Purchases
+
+
+
+
+ | ID |
+ User |
+ Product |
+ Quantity |
+ Date |
+
+
+
+ {% for purchase in recent_purchases %}
+
+ | {{ purchase.id }} |
+ {{ purchase.user.email }} |
+ {{ purchase.product_id }} |
+ {{ purchase.quantity }} |
+ {{ purchase.purchase_date|date:"M d, Y H:i" }} |
+
+ {% empty %}
+
+ | No recent purchases found. |
+
+ {% endfor %}
+
+
+
+
+
+
+