Фикс сериализатора для профиля

main
through-your-tears 9 months ago
parent 95a4a27278
commit 6f2e137bf3

@ -104,8 +104,8 @@ class CustomUserSerializer(serializers.ModelSerializer):
class ProfileSerializer(serializers.ModelSerializer):
user = serializers.StringRelatedField()
friends = serializers.SerializerMethodField(read_only=True)
subscribers = serializers.SerializerMethodField(read_only=True)
count_friends = serializers.SerializerMethodField(read_only=True)
count_subscribers = serializers.SerializerMethodField(read_only=True)
def get_friends(self, obj):
return obj.friends.filter(approved=True).count()
@ -115,4 +115,4 @@ class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = ('user', 'first_name', 'last_name', 'title', 'avatar', 'friends', 'subscribers')
fields = ('user', 'first_name', 'last_name', 'title', 'avatar', 'count_friends', 'count_subscribers')

Loading…
Cancel
Save