How to set current user to user field in Django Rest Framework?

Off the top of my head, you can just override the perform_create() method:

class PhotoListAPIView(generics.ListCreateAPIView):
    ...
    def perform_create(self, serializer):
        serializer.save(user=self.request.user)

Give that a shot and let me know if it works

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)