[Answered ]-How can I show specific users data into the serializer through django?

1👍

You can override the to_representation method in your serializer

class PortfolioSerializer(serializers.ModelSerializer):
    
    user = serializers.ReadOnlyField(source='user.get_full_name')
    class Meta:
        model = Portfolio
        fields = (
            'user'
        )
    
    def to_representation(self, instance):
        data = super().to_representation(instance)
        data["my_shares"] = MySharesSerializer(instance.my_shares.all(), many=True).data
        return data

👤gardi

Leave a comment