1👍
✅
Could you check if this code works for you?
class FinalLevelRepliesSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = Comment
fields = ['id', 'text', 'owner', 'article', 'parent']
class FirstLevelRepliesSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
reply_set = FinalLevelRepliesSerializer(many=True, read_only=True)
class Meta:
model = Comment
fields = ['id', 'text', 'owner', 'article', 'parent', 'reply_set']
class CommentSerializer(serializers.ModelSerializer):
owner = serializers.ReadOnlyField(source='owner.username')
reply_set = FirstLevelRepliesSerializer(many=True, read_only=True)
class Meta:
model = Comment
fields = ['id', 'text', 'owner', 'article', 'parent', 'reply_set']
Source:stackexchange.com