Get current user in Model Serializer

前端 未结 4 698
醉话见心
醉话见心 2021-01-31 14:53

Is it possible to get the current user in a model serializer? I\'d like to do so without having to branch away from generics, as it\'s an otherwise simple task that must be done

4条回答
  •  耶瑟儿~
    2021-01-31 15:09

    A context is passed to the serializer in REST framework, which contains the request by default. So you can just use self.context['request'].user inside your serializer.

提交回复
热议问题