Assignment to a reverse OneToOne overwrites related object's PK
example models:
class User(models.Model):
name = models.CharField(max_length=10)
def __unicode__(self):
return '<USER: %s>' % self.name
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile', null=True)
When I try to assign a UserProfile instance to a User instance's “profile” attribute, UserProfile's PK AutoField gets overwritten with the User instance:
>>> u = User(name='test')
>>> p = UserProfile()
>>> print p.id, p.user
None None
>>> u.profile = p
>>> print p.id, p.user
<USER test> <USER test>
# Expected: None <USER test>
milestone: |
→ 1.1
|
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to ianschenck
|
Cc: |
dgouldin@… added
|
Has patch: |
set
|
Triage Stage: |
Accepted → Ready for checkin
|
Triage Stage: |
Ready for checkin → Accepted
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Oh, wait, needs a test.