1
If you want to save the currently loggedin user, you can override the perform_create()
method of the ProfileCreateAPIView
.
In that method, you can pass the user
argument with value as request.user
. DRF will use this extra value along with the fields defined in the serializer to create Profile
instance.
class ProfileCreateAPIView(CreateAPIView):
queryset = Profile.objects.all()
serializer_class = ProfileCreateSerializer
def perform_create(self, serializer):
serializer.save(user=self.request.user) # pass the user field
Source:stackexchange.com