Django Rest Framework - Get related model field in serializer

Simple as that, adding the WineSerializer as a field solved it.

class BottleSerializer(serializers.HyperlinkedModelSerializer):
    wine = WineSerializer(source='wine')

    class Meta:
        model = Bottle
        fields = ('url', 'wine', 'user', 'date_rated', 'rating', 'comment', 'get_more')

with:

class WineSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Wine
        fields = ('id', 'url', 'color', 'country', 'region', 'appellation')

Thanks for the help @mariodev :)


If you want to get specific field you can use Serializer Fields

https://www.django-rest-framework.org/api-guide/fields/

    class BottleSerializer(serializers.HyperlinkedModelSerializer):
        winecolor = serializers.CharField(read_only=True, source="wine.color")

        class Meta:
            model = Bottle
            fields = ('url', 'winecolor', 'user', 'date_rated', 'rating', 'comment', 'get_more')