title: django serialize foreign key objects
body: <ul>
  <li><a href="https://stackoverflow.com/questions/4015229/serialize-django-model-with-foreign-key-models">Serialize django model with foreign key models</a></li>
  <li><a href="https://stackoverflow.com/questions/3753359/serializing-foreign-key-objects-in-django">Serializing Foreign Key objects in Django</a></li>
  <li><a href="https://stackoverflow.com/questions/2832997/get-foreign-key-objects-in-a-single-query-django">get foreign key objects in a single query - Django</a></li>
  </ul>
  
  <p>There are couple of question asking for the same thing already. But they are from 2010, and it didn't help me so much. So I figure it maybe been some update to this front since 2010?</p>
  
  <p>On google I found this <a href="http://mohtasham.info/article/serializing-foreign-key-django-model/" rel="nofollow noreferrer">link</a>, which explain usage of <a href="http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys" rel="nofollow noreferrer">natural keys</a>. However my problem concerns of getting foreign objects from <code>django.contrib.auth.models.User</code> so it doesn't help.</p>
  
  <p>My problem is as following. I want to serialize the QuerySet so I get the foreign key objects also, because I want to pass it as JSON to the client. The serializer from <code>django.core</code> doesn't do that. So in my case to simply the problem I had added another field to the model to contain the value I need from the foreign object. But it however introduce redundant data.</p>
  
  <p>My example model it contains the <code>username</code> which I would like if possible remove, and instead get it by the foreign key.</p>
  
  <pre><code>    user = models.ForeignKey(User)
      username = models.CharField(max_length=100, null=False)
  </code></pre>