title: Django REST Framework: object is None only on one attribute, but not other
body: <p>I have been having trouble understanding why the object (obj) passed into field_to_native() changes from Nonetype to a correct object once I change the attribute...</p>
  
  <p>Here's the original issue: <a href="https://stackoverflow.com/questions/18949156/splitting-model-instance-for-serializer-into-3-different-fields">Splitting model instance for serializer into 3 different fields</a></p>
  
  <p>mariodev from stackoverflow helped me on the original issue, but a strange bug both of us cannot figure out:</p>
  
  <p>Here's the code where it seems to have the problem:</p>
  
  <pre><code>COORD = dict(x=0, y=1, z=2)
  class CoordField(serializers.Field):
      def field_to_native(self, obj, field_name):
          #retrieve and split coords
          coor = obj.xyz.split('x')
          return int(coor[COORD[field_name]])
  
  class NoteSerializer(serializers.ModelSerializer):
      owner = serializers.Field(source='owner.username')
      firstname = serializers.Field(source='owner.first_name')
      lastname = serializers.Field(source='owner.last_name')
      x = CoordField()
      y = CoordField()
      z = CoordField()
  
  
  class Meta:
      model = Note
      fields = ('id','owner','firstname','lastname','text','color','time','x', 'y', 'z')
  </code></pre>
  
  <p>xyz is a instance in the model Note. According to the traceback, when I do obj.xyz, the obj = None.</p>
  
  <p>Weirdly, if I do obj.color, the obj returns correctly (Note: someuser)</p>
  
  <p>I don't understand how the obj can change just by changing the attribute.</p>
  
  <p>What's beyond me is that the JSON data 'x' 'y' and 'z' ARE being passed to the view, and my div boxes get the correct left, top, and z-index CSS data. If this works, why am I getting an error?</p>
  
  <p>If there's an error, why is the data still getting through?</p>
  
  <pre><code>style="left: 343px; top: 110px; z-index: 3;"
  </code></pre>
  
  <p>As you can see, the x,y,z DID pass through.</p>
  
  <p>Any enlightenment would be wonderful! Thanks a bunch! </p>
  
  <p>Here's the traceback in text view:</p>
  
  <pre><code>Traceback:
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
    140.                     response = response.render()
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/django/template/response.py" in render
    105.             self.content = self.rendered_content
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/rest_framework/response.py" in rendered_content
    59.         ret = renderer.render(self.data, media_type, context)
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/rest_framework/renderers.py" in render
    582.         post_form = self.get_rendered_html_form(view, 'POST', request)
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/rest_framework/renderers.py" in get_rendered_html_form
    485.             data = serializer.data
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/rest_framework/serializers.py" in data
    510.                 self._data = self.to_native(obj)
  File "/home1/thecupno/python2.7/lib/python2.7/site-packages/rest_framework/serializers.py" in to_native
    309.             value = field.field_to_native(obj, field_name)
  File "/home1/thecupno/django/notes/desk/serializers.py" in field_to_native
    10.         coor = obj.xyz#.split('x')      &lt;-- I commented out .split, and the problem still persists.
  Exception Type: AttributeError at /desk/restnote/
  Exception Value: 'NoneType' object has no attribute 'xyz'
  </code></pre>