mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-27 17:14:55 +00:00
user edit api
This commit is contained in:
@ -23,7 +23,8 @@ class UserManagementListSerializer(serializers.ModelSerializer):
|
|||||||
user management serializer
|
user management serializer
|
||||||
"""
|
"""
|
||||||
name = serializers.SerializerMethodField()
|
name = serializers.SerializerMethodField()
|
||||||
phone_number = serializers.SerializerMethodField()
|
country_code = serializers.SerializerMethodField()
|
||||||
|
phone = serializers.SerializerMethodField()
|
||||||
user_type = serializers.SerializerMethodField()
|
user_type = serializers.SerializerMethodField()
|
||||||
is_active = serializers.SerializerMethodField()
|
is_active = serializers.SerializerMethodField()
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ class UserManagementListSerializer(serializers.ModelSerializer):
|
|||||||
meta class
|
meta class
|
||||||
"""
|
"""
|
||||||
model = USER
|
model = USER
|
||||||
fields = ('id', 'name', 'email', 'phone_number', 'user_type', 'is_active')
|
fields = ('id', 'name', 'email', 'country_code', 'phone', 'user_type', 'is_active')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_name(obj):
|
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
|
return f"{obj.first_name} {obj.last_name}" if obj.last_name else obj.first_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_phone_number(obj):
|
def get_country_code(obj):
|
||||||
"""
|
"""
|
||||||
:param obj: user object
|
:param obj: user object
|
||||||
:return: user phone number
|
:return: user phone number
|
||||||
"""
|
"""
|
||||||
if profile := obj.guardian_profile.all().first():
|
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():
|
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:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class UserManagementViewSet(GenericViewSet, mixins.ListModelMixin,
|
|||||||
api to manage (list, view, edit) user
|
api to manage (list, view, edit) user
|
||||||
"""
|
"""
|
||||||
serializer_class = UserManagementListSerializer
|
serializer_class = UserManagementListSerializer
|
||||||
permission_classes = []
|
permission_classes = [IsAuthenticated, AdminPermission]
|
||||||
queryset = USER.objects.filter(is_superuser=False
|
queryset = USER.objects.filter(is_superuser=False
|
||||||
).prefetch_related('guardian_profile',
|
).prefetch_related('guardian_profile',
|
||||||
'junior_profile'
|
'junior_profile'
|
||||||
|
|||||||
Reference in New Issue
Block a user