title: django query set values() specific fields to include user profile
body: <p>I have 2 django models like this:</p>
  
  <pre><code>class UserProfile(models.Model):
      user             = models.OneToOneField(User)
      organisation     = models.CharField(max_length=200)
  
  class Submission(models.Model):
      user             = models.ForeignKey(User)
      date_submission  = models.DateTimeField(db_index=True, default=datetime.now())
      date_published   = models.DateTimeField(db_index=True, null=True)
      status           = models.CharField(db_index=True, max_length=4000)
      logfile          = models.TextField(db_index=False)
  </code></pre>
  
  <p>where each 'Submission' object is owned by a normal django user, and each user has a UserProfile configured using the AUTH_PROFILE_MODULE in the normal way.</p>
  
  <p>This works as you would expect, i can see the organisation field of the UserProfile object:</p>
  
  <pre><code>Submission.objects.all()[0].user.userprofile.organisation
  </code></pre>
  
  <p>When i want to serialize the Submissions list (for export to json) normally i use:</p>
  
  <pre><code>Submission.objects.all().values()
  # or for more control of fields
  Submission.objects.all().values('status', 'date_submission')
  # to traverse a relationship.. get info from the User object
  Submission.objects.all().values('user__username')
  </code></pre>
  
  <p>.. these work fine. BUT my problem is that i cannot:</p>
  
  <pre><code>Submission.objects.all().values('user__userprofile__organisation')
  
  raise FieldError("Invalid field name: '%s'" % name)
  django.core.exceptions.FieldError: Invalid field name: 'user__userprofile__organisation'
  </code></pre>
  
  <p>so it seems that the UserProfile is a 'special case'. This was discussed here:
  <a href="https://stackoverflow.com/questions/6305017/django-query-call-values-on-user-userprofile">Django query : Call values() on user__userprofile</a></p>
  
  <p>but the solution doesn't help me (i'm fairly sure..)</p>
  
  <p>Is this a limitation of the values() method ? does anyone know a way to get the same output of values() but able to traverse the UserProfile model ?</p>
  
  <p>thanks for any ideas</p>
  
  <p>-i</p>