[Fixed]-How do I use perform_create to set a field automatically in Django Rest Framework?

17👍

You should simply add the professor as you did with the author:

serializer.save(
    author=self.request.user,
    professor_id=self.kwargs.get('pk'),
)

Note that in order to avoid to pull the professor from the DB, I set the FK explicitly instead.

Leave a comment