diff --git a/nablapps/core/views.py b/nablapps/core/views.py index e3ca6db3..d5850da7 100644 --- a/nablapps/core/views.py +++ b/nablapps/core/views.py @@ -70,7 +70,19 @@ def get_context_data(self, **kwargs): # TODO: fiks SQL query context["bedpres_leaderboard"] = EventRegistration.objects.raw( - """SELECT COUNT(attendance_registration), username from EventRegistration JOIN users WHERE EventRegistration.userId = users.id JOIN event where EventRegistration.eventId = event.id WHERE EventRegistration.date > "2024 - 08 - 10" AND EventRegistration.date < "2025 - 06 - 20" AND event.is_bedpres GROUP BY userId LIMIT 10""" + """SELECT 1 as id, + COUNT(r.attendance_registration) AS num_bedpres, + u.username, + u.first_name, u.last_name + FROM content_eventregistration AS r + INNER JOIN accounts_nablauser AS u ON r.user_id = u.id + INNER JOIN content_event AS e ON r.event_id = e.id + WHERE r.date > '2024-08-10' + AND r.date < '2025-06-20' + AND e.is_bedpres = 1 + GROUP BY r.user_id + ORDER BY num_bedpres DESC + LIMIT 10""" ) return context diff --git a/templates/front_page.html b/templates/front_page.html index 0cc3676f..2f3b2dcf 100644 --- a/templates/front_page.html +++ b/templates/front_page.html @@ -73,8 +73,8 @@
BrukerAntall Bedpres {% for t in bedpres_leaderboard %} - {{t.user.get_full_name}} - {{t.length}} + {{t.first_name}} {{t.last_name}} + {{t.num_bedpres}} {% endfor %}