Hi Julien, Just gave that a go, getting an error:
'User' object has no attribute 'threads' I'm guessing that because I am referring to the User model, which has no direct relation to the Thread module, this won't work? Julien wrote: > Hi, how about this? (I haven't tested it myself) > > Models: > ------- > > class UserProfile(models.Model): > user = models.ForeignKey(User, unique=True) > friends = models.ManyToManyField(User, blank=True, > related_name='friends') > > class Thread(models.Model): > title = models.CharField(maxlength=200) > users = models.ManyToManyField(User, related_name='threads') > > View: > ----- > > # get profile > profile = get_object_or_404(UserProfile, > user__id__exact=request.user.id) > > # get friends for user > friends = profile.friends.all() > > # get threads for friends > threads = [] > for friend in friends: > thread.append([friend, friend.threads.all()]) > > > On Feb 23, 8:34 am, Darthmahon <[EMAIL PROTECTED]> wrote: > > Hey, > > > > I have three models but I can only handle the relationship between two > > at any one time. > > > > Basically I have a page that needs to show a threads the current > > user's friends are currently participating in. I.E. something like > > this: > > > > Thread: ABC > > Participating: Friend 1 > > > > Thread: XYZ > > Participating: Friend 1, Friend 2, Friend 3 > > > > Here are my models (both of which refer to the default Auth model): > > > > ---------------------------------- > > File: /people/models.py > > ---------------------------------- > > > > class UserProfile(models.Model): > > > > user = models.ForeignKey(User, unique=True) > > friends = models.ManyToManyField(User, blank=True, > > related_name='friend_set') > > > > ---------------------------------- > > File: /thread/models.py > > ---------------------------------- > > > > class Thread(models.Model): > > > > title = models.CharField(maxlength=200) > > users = models.ManyToManyField(User, related_name='users') > > > > ---------------------------------- > > > > Now here is my view file: > > > > ---------------------------------- > > File: /people/views.py > > ---------------------------------- > > > > def index(request): > > > > # get profile > > profile = get_object_or_404(UserProfile, > > user__id__exact=request.user.id) > > > > # get friends for user > > friends = profile.friends.all() > > > > # get threads for friends > > ??????????? > > > > ---------------------------------- > > > > As you can see, I don't know what to do now I need to get the threads > > for each individual user. I don't need to group them in a special way, > > I just want to print the threads my friends are currently > > participating in an alphabetical list. > > > > I did wonder if I should just edit the UserProfile model like this? > > > > ---------------------------------- > > File: /people/models.py > > ---------------------------------- > > > > class UserProfile(models.Model): > > > > user = models.ForeignKey(User, unique=True) > > friends = models.ManyToManyField(User, blank=True, > > related_name='friend_set') > > threads = models.ManyToManyField(Thread, blank=True, > > related_name='thread_set') > > > > ---------------------------------- > > > > Any ideas on how to do this? I'm guessing it's probably fairly basic > > but I can't think how I would get around this at the moment (it's been > > a long week!) ;) > > > > Cheers, > > Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" 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-users?hl=en -~----------~----~----~----~------~----~------~--~---

