user edit api

This commit is contained in:
abutalib-kiwi
2023-08-04 16:28:58 +05:30
parent 5f1c645e3a
commit baacb1a18f
2 changed files with 20 additions and 6 deletions

View File

@ -23,7 +23,8 @@ class UserManagementListSerializer(serializers.ModelSerializer):
user management serializer
"""
name = serializers.SerializerMethodField()
phone_number = serializers.SerializerMethodField()
country_code = serializers.SerializerMethodField()
phone = serializers.SerializerMethodField()
user_type = serializers.SerializerMethodField()
is_active = serializers.SerializerMethodField()
@ -32,7 +33,7 @@ class UserManagementListSerializer(serializers.ModelSerializer):
meta class
"""
model = USER
fields = ('id', 'name', 'email', 'phone_number', 'user_type', 'is_active')
fields = ('id', 'name', 'email', 'country_code', 'phone', 'user_type', 'is_active')
@staticmethod
def get_name(obj):
@ -43,15 +44,28 @@ class UserManagementListSerializer(serializers.ModelSerializer):
return f"{obj.first_name} {obj.last_name}" if obj.last_name else obj.first_name
@staticmethod
def get_phone_number(obj):
def get_country_code(obj):
"""
:param obj: user object
:return: user phone number
"""
if profile := obj.guardian_profile.all().first():
return f"+{profile.country_code}{profile.phone}" if profile.country_code and profile.phone else profile.phone
return profile.country_code if profile.country_code else None
elif profile := obj.junior_profile.all().first():
return f"+{profile.country_code}{profile.phone}" if profile.country_code and profile.phone else profile.phone
return profile.country_code if profile.country_code else None
else:
return None
@staticmethod
def get_phone(obj):
"""
:param obj: user object
:return: user phone number
"""
if profile := obj.guardian_profile.all().first():
return profile.phone if profile.phone else None
elif profile := obj.junior_profile.all().first():
return profile.phone if profile.phone else None
else:
return None