[Answer]-Load models and related data

1πŸ‘

βœ…

It looks like you need to define a Serializer for Person and refer to it in your CarSerializer:

class PersonSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Person

    fields = ('id', ...)


# Then use that serializer in CarSerializer:
class CarSerializer(serializers.ModelSerializer):
    owner = PersonSerializer(source='owner')

    class Meta:
        model = Car
        fields = ('id', /*...*/, 'owner')

Check the JSON payload using the DRF browsable API to get your desired data.

πŸ‘€saschwarz

Leave a comment