#11265: ForeignKey/OneToOneField should support user-defined id attribute name
---------------------------------------------------+------------------------
          Reporter:  dstora                        |         Owner:  nobody     
                            
            Status:  new                           |     Milestone:             
                            
         Component:  Database layer (models, ORM)  |       Version:             
                            
        Resolution:                                |      Keywords:  foreign 
key ForeignKey OneToOneField id
             Stage:  Accepted                      |     Has_patch:  1          
                            
        Needs_docs:  1                             |   Needs_tests:  1          
                            
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by k4ml):

 Not sure if this related. This is my models definition:-

 {{{
 from portal.models import User as DrupalUser

 class Profile(models.Model):
     profile_id = models.OneToOneField(DrupalUser, parent_link=False,
 primary_key=True)
     gid = models.ForeignKey(app_group.Group, db_column="gid")
     nama_penuh = models.CharField(max_length=128)

     class Meta:
         db_table = '"app_profile"."profile"'

 >>> from portal.models.app_profile import Profile
 >>> p = Profile.objects.get(pk=1)
 ProgrammingError: column profile.profile_id_id does not exist
 LINE 1: SELECT "app_profile"."profile"."profile_id_id", "app_profile...
 }}}

 `profile_id` is the actual column name in table `app_profile.profile`. My
 initial expectation is to use `db_column` parameter just like the second
 definition for `gid` field.

 I try the patch (against 1.1 release which differ a bit) but got the
 following error:-

 {{{
 >>> from portal.models import User as DrupalUser
 >>> u = DrupalUser.objects.get(pk=1)
 >>> u.name
 u'admin'
 >>> u.profile
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
 ......
 File "/home/kamal/portal/trunk/django/env/lib/python2.5/site-
 packages/django/db/models/fields/related.py", line 273, in __set__
     self.field.name, self.field.rel.to._meta.object_name))
 ValueError: Cannot assign "1": "Profile.profile_id" must be a "User"
 instance.
 }}}

 Before I applied the above patch, there's no `profile` attribute on the
 `User` object.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11265#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to