jira-15 top junior API and default images field

This commit is contained in:
jain
2023-07-06 07:57:53 +05:30
parent 0d143a39ac
commit a80f603614
10 changed files with 243 additions and 9 deletions

View File

@ -129,7 +129,9 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
if image:
filename = f"images/{image.name}"
image_url = upload_image_to_alibaba(image, filename)
print("image_url=====>",image_url)
guardian.image = image_url
print("guardian.image=====>", guardian.image)
guardian.save()
return guardian
@ -192,3 +194,71 @@ class TaskDetailsSerializer(serializers.ModelSerializer):
model = JuniorTask
fields = ['id', 'guardian', 'task_name', 'task_description', 'points', 'due_date', 'image','junior',
'task_status', 'is_active']
class TopJuniorSerializer(serializers.ModelSerializer):
total_points = serializers.SerializerMethodField()
email = serializers.SerializerMethodField('get_auth')
first_name = serializers.SerializerMethodField('get_first_name')
last_name = serializers.SerializerMethodField('get_last_name')
def get_auth(self, obj):
return obj.auth.username
def get_first_name(self, obj):
return obj.auth.first_name
def get_last_name(self, obj):
return obj.auth.last_name
class Meta:
model = Junior
fields = ['id', 'email', 'first_name', 'last_name', 'phone', 'country_code', 'country_name', 'gender', 'dob', 'image', 'junior_code', 'guardian_code', 'referral_code', 'referral_code_used', 'is_active', 'is_complete_profile', 'passcode', 'is_verified', 'created_at', 'updated_at', 'total_points']
def get_total_points(self, obj):
junior_ids_with_total_points = self.context.get('junior_ids_with_total_points')
if junior_ids_with_total_points:
junior_id = obj.id
for item in junior_ids_with_total_points:
if item['junior'] == junior_id:
return item['total_points']
return 0
#
# class TopJuniorSerializer(serializers.ModelSerializer):
# total_points = serializers.SerializerMethodField()
#
# email = serializers.SerializerMethodField('get_auth')
# first_name = serializers.SerializerMethodField('get_first_name')
# last_name = serializers.SerializerMethodField('get_last_name')
#
#
# def get_auth(self, obj):
# return obj.auth.username
#
# def get_first_name(self, obj):
# return obj.auth.first_name
#
# def get_last_name(self, obj):
# print("onbj==>",obj)
# return obj.auth.last_name
#
# class Meta:
# model = Junior
# fields = ['id', 'email', 'first_name', 'last_name', 'phone', 'country_code', 'country_name', 'gender', 'dob', 'image', 'junior_code', 'guardian_code', 'referral_code', 'referral_code_used', 'is_active', 'is_complete_profile', 'passcode', 'is_verified', 'created_at', 'updated_at', 'total_points']
#
# def get_total_points(self, obj):
# total_highest_points = self.context.get('total_highest_points')
# if total_highest_points:
# print("total_highest_points==>",total_highest_points)
# junior_id = obj.id
# print("junior_id==>", junior_id)
# total_points = next((item['total_points'] for item in total_highest_points if item['junior'] == junior_id), 0)
# print("total_points==>", total_points)
# return total_points
# return 0
#