37👍
✅
I think instead of doing that, you should use nested serializers.
Create a BusSerializer
having fields idn
and stops_left
. Then include this serializer in your StopOncomingSerializer
as buses
field with many=True
argument to handle multiple buses
data.
class BusSerializer(serializers.Serializer):
idn = serializers.IntegerField(read_only=True)
stops_left = serializers.IntegerField(read_only=True)
class StopOncomingSerialier(serializers.Serializer):
idn = serializers.IntegerField(read_only=True)
buses = BusSerializer(many=True)
Source:stackexchange.com