I see what you are saying but there are few drawbacks: 1) 2 queries instead of one. 2) When you combine into friends_all or something, you need to keep track of which was friend vs which is user.
I was thinking more on the lines of this: Each User has a UserProfile which i defined. In UserProfile define a onetomany relationship which points to a specific entry in friends relationship so that both friends would point to the same friendship entry. Im not a django or database relationships expert so im not sure if this would even work or whether it would have better performance than 2 queries (usually you select entries more than insert them). Any feedback is welcome Kevin On Dec 22, 12:28 pm, Jason Sidabras <jason.sidab...@gmail.com> wrote: > The way I was thinking of doing it was to have two foreignkeys named > friend1 and friend2 then when you do your list you could run > (something like) > > friends = Friendship.objects.get(friend1__exact=user) > and > friends2 = Friendship.objects.get(friend2__exact=user) > > Then you have a complete instance of the friends. I'm not by a django > computer right now > to figure it out but friends and friends2 could be added together to > pass one variable. > > On Dec 22, 10:10 am, kev <kevinri...@gmail.com> wrote: > > > Hello, > > Im reading a django book and it adds friends to user authentication > > system by making: > > > (was .96) > > > class Friendship(models.Model): > > from_friend = models.ForeignKey( > > User, related_name='friend_set' > > ) > > to_friend = models.ForeignKey( > > User, related_name='to_friend_set' > > ) > > def __str__(self): > > return '%s, %s' % ( > > self.from_friend.username, > > self.to_friend.username > > ) > > class Admin: > > pass > > class Meta: > > unique_together = (('to_friend', 'from_friend'), ) > > > But for this to work, you have to add friendship both ways. Ex/ user1 -> > > user2 and user2 -> user1 which means almost duplicate entries in > > > this model. And anytime you modify one friendship, you have to do the > > same to the other one. > > > Is there a better way to do this so that only one entry exists in the > > db? Any suggestions are welcome! > > > Kevin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---