title: Django Rest Framework: Saving ForeignKey inside OneToOne model
body: <p>I have 2 models that are OneToOne related and model that is FK to 2nd model</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Legal(TimeStampedModel):
       name = models.CharField('Name', max_length=255, blank=True)
  
  class LegalCard(TimeStampedModel):
      legal = models.OneToOneField('Legal', related_name='legal_card', on_delete=models.CASCADE)
      branch = models.ForeignKey('Branch', related_name='branch', null=True)
      post_address = models.CharField('Post address', max_length=255, blank=True)
  
  class Branch(TimeStampedModel):
      name = models.CharField('Name',max_length=511)
      code = models.CharField('Code', max_length=6)
  </code></pre>
  
  <p>Using DRF I made them to behave as single model so I can create or update both:</p>
  
  <p><strong>serializer.py</strong></p>
  
  <pre><code>class LegalSerializer(serializers.ModelSerializer):
  
      branch = serializers.IntegerField(source='legal_card.branch', allow_null=True, required=False)
      post_address = serializers.CharField(source='legal_card.post_address', allow_blank=True, required=False)
  
      class Meta:
          model = Legal
          fields = ('id',
                    'name',
                    'branch',
                    'post_address',
                    )
          depth = 2
  
  
      def create(self, validated_data):
          legal_card_data = validated_data.pop('legal_card', None)
          legal = super(LegalSerializer, self).create(validated_data)
          self.update_or_create_legal_card(legal, legal_card_data)
          return legal
  
      def update(self, instance, validated_data):
          legal_card_data = validated_data.pop('legal_card', None)
          self.update_or_create_legal_card(instance, legal_card_data)
          return super(LegalSerializer, self).update(instance, validated_data)
  
      def update_or_create_legal_card(self, legal, legal_card_data):
          LegalCard.objects.update_or_create(legal=legal, defaults=legal_card_data)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code> class LegalDetailView(generics.RetrieveUpdateDestroyAPIView):
          queryset = Legal.objects.all()
          serializer_class = LegalSerializer
  </code></pre>
  
  <p>I'm trying to save this by sending FK as integer (I just want to post id of the branch), but I receive error</p>
  
  <pre><code>ValueError: Cannot assign "2": "LegalCard.branch" must be a "Branch" instance.
  </code></pre>
  
  <p>Is there any way to pass over only ID of the branch?</p>
  
  <p>Thank you</p>