title: Django making sure user and user profile have same pk
body: <p>Right now I'm using Django's built in admin system to manage users, to which I've attached a profile to contain additional data using the following:</p>
  
  <pre><code>class Profile(models.Model):
      user = models.OneToOneField(User, editable = False)
      # Data fields here...
  </code></pre>
  
  <p>As it stands the User and Profile pk (and accordingly id number) will be the same if and only if the profile is created right after the user is created. I could guarantee that this would be the case during the registration process, and while that would cover most uses, creating users with the admin interface could cause mismatched ids to occur. Thus this does not seem like a very robust way to solve this problem and I'd like to hardcode the pk's to be the same. I'm not sure how to do this.</p>
  
  <p>I thought the following would work:</p>
  
  <pre><code>profile_id = models.IntegerField(default=user.pk, editable = False, 
                                   primary_key = True)
  </code></pre>
  
  <p>But it gives me the error:</p>
  
  <pre><code>AttributeError: 'OneToOneField' has no attribute 'pk'
  </code></pre>
  
  <p>What's the best way to guarantee that the profile and user have the same pk? Note: I'd really rather not deal with extending the base user model as using the OneToOneField to link the two seems to be sufficient for all my needs. </p>
  
  <p>Thanks!</p>
  
  <p><strong>[edit]</strong></p>
  
  <p>My reasoning for asking the question:</p>
  
  <p>My immediate problem was that I wanted a dictionary of values of the User's Profile, which I was retrieving using<code>profile_values = Profile.objects.filter(pk=user.id).values()[0]</code>. This highlighted the bug, and I "hacked" around it last night using <code>pk=user.profile.id</code> instead. In the light of the morning this does not seem like such a terrible hack. However, it seems like having pk discrepancies could lead to quiet and hard to catch bugs down the line, and thus forcing them to match up would be a Good Idea. But I'm new to Django so I'd entirely accept that it is, in fact, never a problem if you're writing your code correctly. That said, for almost academic reasons, I'd be curious to see how this <em>might</em> be solved.  </p>
  
  <p><strong>[/edit]</strong></p>