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
Source:stackexchange.com