Re: Return FK model
@Javier, not sure.. I've used user profiles on my past sites because that's what I was told to do a while ago, if inheritance works with authentication and the admin, I would definitely go that route. Also, @Yanik, I realized my UserProfile model example above was wrong, the user relation should be OneToOneField, not ForeignKey. On Thu, Sep 3, 2009 at 10:49 AM, Javier Guerrawrote: > > On Thu, Sep 3, 2009 at 10:41 AM, Ben Davis wrote: > > The django docs suggest using a UserProfile model when you need to add > more > > information about a user: > > > http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users > > slightly OT: is there any advantage to use profiles instead of table > inheritance? > > I know the userprofiles were the only choice before there was table > inheritance; but is it still the best way? > > -- > Javier > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Return FK model
On Thu, Sep 3, 2009 at 10:41 AM, Ben Daviswrote: > The django docs suggest using a UserProfile model when you need to add more > information about a user: > http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users slightly OT: is there any advantage to use profiles instead of table inheritance? I know the userprofiles were the only choice before there was table inheritance; but is it still the best way? -- Javier --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Return FK model
True, you wouldn't be able to modify the auth.User model. Though you're wrong about what would happen if you were able to. What I'm saying is with a ManyToMany field, the relationship is with itself (User), so it would return User objects. The django docs suggest using a UserProfile model when you need to add more information about a user: http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users What you could do is this. Create a UserProfile model with the friends reflexive relationship: class UserProfile(models.Model): user = ForeignKey(User) friends = ManyToManyField(UserProfile) then you could do: some_user = UserProfile.objects.get(user=X) his_friends = some_user.friends This would return UserProfile objects, though. So if you wanted User objects, you could do his_friends = some_user.friends.select_related('user') This would pull all this user's friends, plus their information from the auth_user table in one query, so while looping through their friends, you access their user information like so: for friend in his_friends: this_friends_user_acct = friend.user Make sense? On Thu, Sep 3, 2009 at 10:17 AM, Yanikwrote: > > Well, I can't add very well add fields to the Auth.User. But even if I > could, user.friends would get me instances of "Friend" model, not > "User" model. > > On Sep 3, 11:13 am, Ben Davis wrote: > > It looks you're setting a many-to-many reflexive (circular) relationship > > between users. It seems it would be better to add a ManyToManyField on > the > > User model, eg: > > > > class User(models.Model): > > ... > > friends = ManyToManyField(User) > > > > Then you could just use "user.friends" > > > > On Thu, Sep 3, 2009 at 9:50 AM, Yanik wrote: > > > > > Let's say I have a model "Friends" that looks something like: > > > > > class Friend(models.Model): > > >user = models.ForeignKey(User) > > >friend = models.ForeignKey(User, related_name="friend") > > > > > I want a list of "User" instances of a user's friends. Is my only > > > option to: > > > > > 1) Get list of "Friends" > > > 2) Then get list of "Users" where id in friends.value_llist('id') > > > > > Or is there a way to do a query on the "Friend" model and as to return > > > "User" instances of friends? > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Return FK model
Well, I can't add very well add fields to the Auth.User. But even if I could, user.friends would get me instances of "Friend" model, not "User" model. On Sep 3, 11:13 am, Ben Daviswrote: > It looks you're setting a many-to-many reflexive (circular) relationship > between users. It seems it would be better to add a ManyToManyField on the > User model, eg: > > class User(models.Model): > ... > friends = ManyToManyField(User) > > Then you could just use "user.friends" > > On Thu, Sep 3, 2009 at 9:50 AM, Yanik wrote: > > > Let's say I have a model "Friends" that looks something like: > > > class Friend(models.Model): > > user = models.ForeignKey(User) > > friend = models.ForeignKey(User, related_name="friend") > > > I want a list of "User" instances of a user's friends. Is my only > > option to: > > > 1) Get list of "Friends" > > 2) Then get list of "Users" where id in friends.value_llist('id') > > > Or is there a way to do a query on the "Friend" model and as to return > > "User" instances of friends? > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Return FK model
It looks you're setting a many-to-many reflexive (circular) relationship between users. It seems it would be better to add a ManyToManyField on the User model, eg: class User(models.Model): ... friends = ManyToManyField(User) Then you could just use "user.friends" On Thu, Sep 3, 2009 at 9:50 AM, Yanikwrote: > > Let's say I have a model "Friends" that looks something like: > > class Friend(models.Model): >user = models.ForeignKey(User) >friend = models.ForeignKey(User, related_name="friend") > > I want a list of "User" instances of a user's friends. Is my only > option to: > > 1) Get list of "Friends" > 2) Then get list of "Users" where id in friends.value_llist('id') > > Or is there a way to do a query on the "Friend" model and as to return > "User" instances of friends? > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Return FK model
Let's say I have a model "Friends" that looks something like: class Friend(models.Model): user = models.ForeignKey(User) friend = models.ForeignKey(User, related_name="friend") I want a list of "User" instances of a user's friends. Is my only option to: 1) Get list of "Friends" 2) Then get list of "Users" where id in friends.value_llist('id') Or is there a way to do a query on the "Friend" model and as to return "User" instances of friends? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---