Skip to content

Commit

Permalink
refactor: set user instead of id (in user-public serializer)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmooHashem committed Nov 11, 2024
1 parent c3b6b1e commit da78826
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions apps/accounts/serializers/user_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,15 @@ class Meta:


class UserPublicInfoSerializer(serializers.ModelSerializer):
truncated_username = serializers.SerializerMethodField()
user = serializers.SerializerMethodField()

def get_truncated_username(self, obj):
username = obj.username
if username and len(username) > 4:
return username[-4:]
return username
def get_user(self, obj):
return obj.id

class Meta:
model = User
fields = ['id', 'truncated_username', 'first_name',
'last_name', 'bio', 'profile_image', 'gender']
fields = ['user', 'first_name', 'last_name',
'bio', 'profile_image', 'gender']
read_only_fields = fields


Expand Down

0 comments on commit da78826

Please sign in to comment.