Open akhilmathew001 opened 2 years ago
I guess this happens because, in the update_or_create_reverse_relations
method, the related_data
is got from self.get_initial()
which will be an empty OrderedDict
, since the initial_data
in the case of creating multiple objects is a list (check the get_initial
method for more context).
I hit this issue as well when making a custom bulk-create
endpoint that receives a list of serialized objects and calls
serializer = self.get_serializer(data=request.data, many=True)
I only discovered later that Model
s with nested Model
s within them never created those nested models.
To work around this, I had to manually iterate of the list
in request.data
and call self.get_serializer()
each time within the loop.
I have a serializer like this. I used to pass multiple objects with nested relations to this serializer with many=True enabled from the view. Sample JSON is as follows;
Here Alarm object is getting created, but its nested relations are not created. What can be wrong here