accounts: add user profile and user update api
This commit is contained in:
28
core/apps/accounts/serializers/user.py
Normal file
28
core/apps/accounts/serializers/user.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.accounts.models import User
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = [
|
||||
'id', 'phone', 'indentification_num', 'profile_image', 'first_name', 'last_name', 'email'
|
||||
]
|
||||
|
||||
|
||||
class UserUpdateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = [
|
||||
'indentification_num', 'profile_image', 'first_name', 'last_name', 'email'
|
||||
]
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
instance.indentification_num = validated_data.get('indentification_num', instance.indentification_num)
|
||||
instance.profile_image = validated_data.get('profile_image', instance.profile_image)
|
||||
instance.first_name = validated_data.get('first_name', instance.first_name)
|
||||
instance.last_name = validated_data.get('last_name', instance.last_name)
|
||||
instance.email = validated_data.get('email', instance.email)
|
||||
instance.save()
|
||||
return instance
|
||||
Reference in New Issue
Block a user