Django REST Framework : "This field is required." with required=False and unique_together : <p>I want to save a simple model with Django REST Framework. The only requirement is that <code>UserVote.created_by</code> is set automatically within the <code>perform_create()</code> method. This fails with this exception:</p>

<pre><code>{
    "created_by": [
        "This field is required."
    ]
}
</code></pre>

<p>I guess it is because of the unique_together index.</p>

<p>models.py:</p>

<pre><code>class UserVote(models.Model):
    created_by = models.ForeignKey(User, related_name='uservotes')
    rating = models.ForeignKey(Rating)

    class Meta:
        unique_together = ('created_by', 'rating')
</code></pre>

<p>serializers.py</p>

<pre><code>class UserVoteSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(read_only=True)
    created_by = UserSerializer(read_only=True)

    class Meta:
        model = UserVote
        fields = ('id', 'rating', 'created_by')
</code></pre>

<p>views.py</p>

<pre><code>class UserVoteViewSet(viewsets.ModelViewSet):
    queryset = UserVote.objects.all()
    serializer_class = UserVoteSerializer
    permission_classes = (IsCreatedByOrReadOnly, )

    def perform_create(self, serializer):
        serializer.save(created_by=self.request.user)
</code></pre>

<p>How can I save my model in DRF without having the user to supply <code>created_by</code> and instead set this field automatically in code?</p>

<p>Thanks in advance!</p>
