From da7882696375ab133fd5af5f162cbb9c7397cb33 Mon Sep 17 00:00:00 2001 From: Seyed Alireza Hashemi Date: Mon, 11 Nov 2024 18:46:34 +0330 Subject: [PATCH] refactor: set user instead of id (in user-public serializer) --- apps/accounts/serializers/user_serializer.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/accounts/serializers/user_serializer.py b/apps/accounts/serializers/user_serializer.py index c1dae596..2260cf78 100644 --- a/apps/accounts/serializers/user_serializer.py +++ b/apps/accounts/serializers/user_serializer.py @@ -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