[Answered ]-How to create model in Django REST with userID from authentication

2👍

You should have a look at the rest framework tutorial. You can pass the user_id or user instance to the save method of your serializer. This can be done in the perform_create method of your ViewSet

class SnippetViewSet(viewsets.ModelViewSet):
    """
    This viewset automatically provides `list`, `create`, `retrieve`,
    `update` and `destroy` actions.
    """
    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

Leave a comment