[Answered ]-DRF nested router serializer source fields from url

1👍

In this case you can pass the author_pk to save() to automatically set the author id of the newly created book, as explained here:

    def create(self, request, author_pk):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save(author_id=author_pk) 
        return Response(serializer.data)

Leave a comment