[Answered ]-Update django model database with ForeignKey by using serializer

1👍

You pass the user as parameter, so:

if serializer.is_valid():
    instance = serializer.save(user=request.user)
        return Response({'status': 'success', 'data': serializer.data}, status=status.HTTP_200_OK)

Note: It is normally better to make use of the settings.AUTH_USER_MODEL [Django-doc] to refer to the user model, than to use the User model [Django-doc] directly. For more information you can see the referencing the User model section of the documentation.

Leave a comment