title: How do I use perform_create to set a field automatically in Django Rest Framework?
body: <p>I am trying to create a REST Api for my application.</p>
  
  <p><strong>urls.py</strong> in the application directory looks like this:</p>
  
  <pre><code>urlpatterns = [
      url(
          r'^professors/(?P&lt;pk&gt;[0-9]+)/reviews/$',
          views.ProfessorReviewList.as_view(),
          name = 'user-review-list',
      )
  ]
  </code></pre>
  
  <p><strong>serializers.py</strong></p>
  
  <pre><code>class ProfessorSerializer(serializers.HyperlinkedModelSerializer):
      reviews = serializers.HyperlinkedIdentityField(view_name='professor-review-list')
      class Meta:
          model = Professor
          fields = (
              'url', 'name', 'name_code', 'university',
              'department', 'total_rating_points',
              'number_of_reviews', 'rating', 'reviews',
          )
  
  class ReviewSerializer(serializers.HyperlinkedModelSerializer):
      author = serializers.ReadOnlyField(source='author.username')
  
      class Meta:
          model = Review
          fields = (
              'url', 'author', 'professor',
              'created', 'updated', 'rating', 'text'
          )
  </code></pre>
  
  <p>And finally, my <strong>views.py</strong> looks like this:</p>
  
  <pre><code>class ProfessorReviewList(generics.ListCreateAPIView):
      queryset = Review.objects.all()
      serializer_class = ReviewSerializer
      def get_queryset(self):
          queryset = super(ProfessorReviewList, self).get_queryset()
          return queryset.filter(professor__pk=self.kwargs.get('pk'))
  
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                            IsAuthorOrReadOnly,)
  
      def perform_create(self, serializer):
          # The request user is set as author automatically.
          serializer.save(author=self.request.user)
  </code></pre>
  
  <p>What I am trying to do is get a list of all the reviews for one particular professor when I go to the URL. I also want to allow users to add a new review at this end-point if they want to. Everything works nicely, but I want a system where the user does not have to choose the professor when creating a review.</p>
  
  <p>Lets say I go to <strong>/professors/1/reviews/</strong>, a list of all the reviews for the professor with pk=1 is obtained. Now, if the user adds a new review, the professor is automatically set to the professor with pk=1. The user does not get to choose. At <strong>/professors/2/reviews/</strong>, the professor field for the review is automatically set to the professor with pk=2 and so on and so on. </p>
  
  <p>How can I do this? Thanks for any help.</p>