Get current user in Model Serializer

前端 未结 4 655
醉话见心
醉话见心 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:11

    I modified the request.data:

    serializer = SectionSerializer(data=add_profile_data(request.data, request.user))
    
    def add_profile_data(data, user):
        data['user'] = user.profile.id
        return data
    

提交回复
热议问题