Serializer ForeignKey results in "Expected a dictionary ..."
<p>My Model:</p>

<pre><code>class Font(ValidateVersionOnSaveMixin, models.Model):
    id = models.UUIDField(primary_key=True, editable=True)  
    name = models.CharField(max_length=100, blank=False, null=False)


class Glyph(ValidateVersionOnSaveMixin, models.Model):
    id = models.UUIDField(primary_key=True, editable=True)  
    unit = models.CharField(max_length=100, blank=False, null=False, unique=True)
    font = models.ForeignKey(Font, on_delete=models.CASCADE)
</code></pre>

<p>I want to post the following JSON to add a Glyph to an already existing Font (having the <code>fontId</code> as ID) object.</p>

<pre><code>{
  fontId: "4a14a055-3c8a-43ba-aab3-221b4244ac73"
  id: "40da7a83-a204-4319-9a04-b0a544bf4440"
  unit: "aaa"
}
</code></pre>

<p>As there is a mismatch between the ForeignKey Field <code>font</code> and the JSON property<code>fontId</code> I am adding <code>source='font'</code> in my Serializer:</p>

<pre><code>class FontSerializer(serializers.ModelSerializer):
    class Meta:
        model = Font
        fields = ('id', 'name')


class GlyphSerializer(serializers.ModelSerializer):
    fontId = FontSerializer(source='font')
    class Meta:
        model = Glyph
        fields = ('id', 'unit', 'fontId' )
</code></pre>

<p>But the result is an BAD REQUEST Error:</p>

<pre><code>{"fontId":{"non_field_errors":["Invalid data. Expected a dictionary, but got str."]}}
</code></pre>

<hr>

<p><strong>Update</strong></p>

<p>The following Serializer gave me the result I was looking for.</p>

<pre><code>class GlyphSerializer(serializers.ModelSerializer):
    fontId = serializers.PrimaryKeyRelatedField(
        queryset=Font.objects.all(),
        required=True,
        source='font',
        write_only=False
    )
    class Meta:
        model = Glyph
        fields = ('id', 'unit', 'version', 'fontId')
</code></pre>