title: Django Rest Framework - Updating a model using 'depth'
body: <p>I'm having a problem updating a relation in a model using <code>ModelSerializer</code> and <code>depth</code>.</p>
  
  <p>I've spent my whole day at this, I don't understand why this is happening.<br>
  This is my set-up (Ignore other relation fields):</p>
  
  <p><strong>models.py</strong>
  </p>
  
  <pre><code>class Condition(models.Model):
      """
      A model representing an electronic component's condition: New, used, pulled, etc...
      """
      name = models.CharField(max_length=50)
  
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
      def __unicode__(self):
          return self.name
  
  class Item(models.Model):
      """
      A model representing an electronic component
      """
  
      COMPONENT_TECH_CHOICES = (
          ('None', 'None'),
          ('TH', 'TH'),
          ('SMT', 'SMT'),
      )
  
      part_number = models.CharField(max_length=100)
      description = models.TextField(blank=True, null=True)
      component_tech = models.CharField(max_length=50,
                                    choices=COMPONENT_TECH_CHOICES,
                                    default=COMPONENT_TECH_CHOICES[0][0])
      rohs = models.BooleanField(default=False)
      # Should be 3-5 digits
      date_code = models.CharField(max_length=10, blank=True, null=True)
  
      manufacturer = models.ForeignKey(Manufacturer, blank=True, null=True, related_name='items')
      package = models.ForeignKey(Package, blank=True, null=True, related_name='items')
      case = models.ForeignKey(Case, blank=True, null=True, related_name='items')
      condition = models.ForeignKey(Condition, blank=True, null=True, related_name='items')
      classification = models.ForeignKey(Classification, blank=True, null=True, related_name='items')
  
      owner = models.ForeignKey('authentication.Account', related_name='items')
  
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
      def __unicode__(self):
          return self.part_number
  </code></pre>
  
  <p><strong>serializers.py</strong></p>
  
  <pre><code>class ConditionSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Condition
  
  class ItemSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = Item
          depth = 1
  </code></pre>
  
  <p>This is the request's payload:</p>
  
  <pre><code>case: {id: 1, name: "Tube", quantity: 100, created_at: "2016-02-13T12:32:27.588000Z",…}
  classification: {id: 1, name: "Resistor", created_at: "2016-02-08T19:31:47.934000Z",…}
  component_tech: "None"
  condition: {id: 1, name: "New", created_at: "2016-02-13T14:00:02.788000Z",…}
  created_at: "2015-12-17T17:33:46.562000Z"
  date_code: "111"
  description: "This is the description of the item"
  id: 1
  manufacturer: {id: 1, name: "Motorola", alias: "On-Semi", created_at: "2015-12-25T16:29:00Z",…}
  owner: {id: 5, password: "pbkdf2_sha256$24000$IUUvIFU6Wjcx$Rayn8i9/QEyA+FyUQWaBOGvJHiz4K/hjYjeaOruDjvA=",…}
  package: {id: 1, name: "DIP-14", created_at: "2016-02-13T14:43:36.246000Z",…}
  part_number: "1N4148"
  rohs: true
  updated_at: "2016-02-19T21:24:58.256000Z"
  </code></pre>
  
  <p>condition has all the required fields (Even though some are hidden).</p>
  
  <p>So, I really don't understand why is this happening.<br>
  DRF version is 3.3.1<br>
  However, I was able to figure that probably the relevant data has not reached <code>validated_data</code>.</p>
  
  <p>At the end I was looking at <a href="https://stackoverflow.com/questions/33077256/django-rest-framework-updating-a-foreign-key">this</a> thread, but all I got from condition in <code>validated_data</code> in <code>update</code> was:</p>
  
  <pre>OrderedDict([(u'name', u'Used')])</pre>
  
  <p>Can anyone please point out what am I doing wrong, and why can't I update the relation in my Item/Condition?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>So, as I was investigating the <code>validated_data</code> issue in the <code>update</code> method in my serializer, I've stumbled upon the point-of-failure.</p>
  
  <p>The <code>initial_data</code> the serializer gets is the request's payload (which is the good data)</p>
  
  <p>However, after <code>serializer.is_valid()</code>, all the nested data disappears. I'm left with no related data. Any ideas why this happens?</p>