title: How to validate read only field in Django Rest Framework
body: <p>I'm trying to add a vote functionality to the code found in <a href="http://www.django-rest-framework.org/#tutorial" rel="nofollow noreferrer">tutorial</a> of Django Rest Framework. On top of Snippet model, I added a Vote model:</p>
  
  <pre><code>class Vote(models.Model):
      created = models.DateTimeField(auto_now_add=True)
      voter = models.ForeignKey(User, on_delete=models.CASCADE)
      snippet = models.ForeignKey(Snippet, related_name='votes', on_delete=models.CASCADE)
  
      class Meta:
          ordering = ('created',)
  </code></pre>
  
  <p>In my serializer, I'm trying to validate the fact that user cannot vote more than once and cannot vote for his own snippet:</p>
  
  <pre><code>class VoteSerializer(serializers.HyperlinkedModelSerializer):
      voter = serializers.ReadOnlyField(source='voter.username',validators=[UniqueValidator(queryset=Vote.objects.all(), message=already_voted)])
      snippet = serializers.PrimaryKeyRelatedField(queryset=Snippet.objects.all())
  
      def validate(self, data):
          snippet = data.get('snippet')
          voter = data.get('voter')
          if voter==data['snippet'].owner:
              raise serializers.ValidationError(u"Voter cannot vote for himself.")
          return data
  </code></pre>
  
  <p>Voter field must be read-only. Problem is that ReadOnlyField is not available in data structure. How can I validate with read only field?</p>
  
  <p>EDIT: here is my view</p>
  
  <pre><code>class VoteViewSet(viewsets.ModelViewSet):
      """
      This viewset automatically provides `list`, `create`, `retrieve`,
      `update` and `destroy` actions.
      """
  
      queryset = Vote.objects.all()
      serializer_class = VoteSerializer
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,
                        IsOwnerOrReadOnly,)
  
  
      def perform_create(self, serializer):
          serializer.save(voter=self.request.user)
  </code></pre>