mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
user edit api
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user