Skip to content

Commit 4d73c3e

Browse files
committed
Day 11: Follower and following count display in profile
1 parent fed52fe commit 4d73c3e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

users/serializers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from users.models import (
77
BlockedUser,
88
CloseFriend,
9+
FollowList,
910
MutedUser,
1011
Profile,
1112
User,
@@ -115,8 +116,8 @@ def validate_password(self, value):
115116

116117

117118
class ProfileSerializer(ModelSerializer):
118-
# followers_count = serializers.SerializerMethodField()
119-
# following_count = serializers.SerializerMethodField()
119+
followers_count = serializers.SerializerMethodField()
120+
following_count = serializers.SerializerMethodField()
120121

121122
class Meta:
122123
model = Profile
@@ -127,8 +128,8 @@ class Meta:
127128
"gender",
128129
"website",
129130
"is_private",
130-
# "followers_count",
131-
# "following_count",
131+
"followers_count",
132+
"following_count",
132133
]
133134
extra_kwargs = {
134135
"user": {"read_only": True},
@@ -150,11 +151,11 @@ def validate(self, attrs):
150151
raise serializers.ValidationError("Enter a valid URL for the website.")
151152
return attrs
152153

153-
# def get_followers_count(self, obj):
154-
# return FollowList.objects.filter(following=obj.user).count()
154+
def get_followers_count(self, obj):
155+
return FollowList.objects.filter(following=obj.user).count()
155156

156-
# def get_following_count(self, obj):
157-
# return FollowList.objects.filter(follower=obj.user).count()
157+
def get_following_count(self, obj):
158+
return FollowList.objects.filter(follower=obj.user).count()
158159

159160

160161
class UserPublicSerializer(serializers.ModelSerializer):

0 commit comments

Comments
 (0)