update position of the junior

This commit is contained in:
jain
2023-07-24 11:00:22 +05:30
parent d86f7d3436
commit a2b4f3b758
2 changed files with 18 additions and 23 deletions

View File

@ -3,7 +3,8 @@
from django.conf import settings
"""Third party Django app"""
from templated_email import send_templated_mail
from .models import JuniorPoints
from django.db.models import F
# junior notification
# email for sending email
# when guardian create junior profile
@ -45,3 +46,14 @@ def junior_approval_mail(guardian, full_name):
}
)
return full_name
def update_positions_based_on_points():
# First, retrieve all the JuniorPoints instances ordered by total_points in descending order.
juniors_points = JuniorPoints.objects.order_by('-total_points')
# Now, iterate through the queryset and update the position field based on the order.
position = 1
for junior_point in juniors_points:
junior_point.position = position
junior_point.save()
position += 1