mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 02:16:16 +00:00
modified top-list api, junior-list api and junior-points api, nodified rank method, added mail for deactivating user from admin
This commit is contained in:
@ -5,7 +5,8 @@ from django.conf import settings
|
||||
from templated_email import send_templated_mail
|
||||
from .models import JuniorPoints
|
||||
from base.constants import NUMBER
|
||||
from django.db.models import F
|
||||
from django.db.models import F, Window
|
||||
from django.db.models.functions.window import Rank
|
||||
# junior notification
|
||||
# email for sending email
|
||||
# when guardian create junior profile
|
||||
@ -61,3 +62,19 @@ def update_positions_based_on_points():
|
||||
junior_point.position = position
|
||||
junior_point.save()
|
||||
position += NUMBER['one']
|
||||
|
||||
|
||||
def get_junior_leaderboard_rank(junior_obj):
|
||||
"""
|
||||
to get junior's position/rank
|
||||
:param junior_obj:
|
||||
:return: junior's position/rank
|
||||
"""
|
||||
queryset = JuniorPoints.objects.prefetch_related('junior', 'junior__auth').annotate(rank=Window(
|
||||
expression=Rank(),
|
||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
||||
)).order_by('-total_points', 'junior__created_at')
|
||||
|
||||
junior = next((query for query in queryset if query.junior == junior_obj), None)
|
||||
|
||||
return junior.rank if junior else None
|
||||
|
Reference in New Issue
Block a user