class MatchSerializer(serializers.ModelSerializer):
winner = AthleteWinnerSerializer(read_only=True)
class Meta:
model = Match
fields = ['uid', 'round_one', 'round_two', 'round_three', 'winner']
In this example the winner is generated in the body of the post api like the example below :
class MatchSerializer(serializers.ModelSerializer): winner = AthleteWinnerSerializer(read_only=True) class Meta: model = Match fields = ['uid', 'round_one', 'round_two', 'round_three', 'winner']
In this example the winner is generated in the body of the post api like the example below :
{ "round_one": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "round_two": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "round_three": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "winner": { "username": "string" } }