Files
zod-backend/web_admin/serializers/analytics_serializer.py
2023-08-11 13:37:44 +05:30

54 lines
1.4 KiB
Python

"""
web_admin analytics serializer file
"""
from rest_framework import serializers
from junior.models import JuniorPoints, Junior
from web_admin.serializers.user_management_serializer import JuniorSerializer
class JuniorLeaderboardSerializer(serializers.ModelSerializer):
name = serializers.SerializerMethodField()
first_name = serializers.SerializerMethodField()
last_name = serializers.SerializerMethodField()
class Meta:
"""
meta class
"""
model = Junior
fields = ('id', 'name', 'first_name', 'last_name', 'is_active', 'image')
@staticmethod
def get_name(obj):
"""
:param obj: junior object
:return: full name
"""
return f"{obj.auth.first_name} {obj.auth.last_name}" if obj.auth.last_name else obj.auth.first_name
@staticmethod
def get_first_name(obj):
"""
:param obj: junior object
:return: first name
"""
return obj.auth.first_name
@staticmethod
def get_last_name(obj):
"""
:param obj: junior object
:return: last name
"""
return obj.auth.last_name
class LeaderboardSerializer(serializers.ModelSerializer):
junior = JuniorLeaderboardSerializer()
rank = serializers.IntegerField()
class Meta:
model = JuniorPoints
fields = ('total_points', 'rank', 'junior')