Skip to content Skip to sidebar Skip to footer

Adding Many Serializer To A Nested Serializer Field

serializers.py class BusOncomingSerializer(serializers.Serializer): idn = serializers.IntegerField(read_only=True) stops_left = serializers.IntegerField(read_only=True) c

Solution 1:

You are passing the data incorrectly to StopOncomingSerializer. Instead of passing bus instances, you should pass the values as list of dictionaries.

Sample Data format:

{
    'idn': 7, 
    'buses': [
        {'idn':3, 'stops_left': 3}, 
        {'idn': 4, 'stops_left':6}
    ]
}

On Python Shell:

In [5]: data = {'idn': 7, 'buses': [{'idn':3, 'stops_left': 3}, {'idn': 4, 'stops_left':6}]}

In [6]: s1 = StopOncomingSerialier(data=data)

In [7]: s1.is_valid()
Out[7]: True

Post a Comment for "Adding Many Serializer To A Nested Serializer Field"