Hi,
I am having difficulties with listing this type of data. Scenario is
as follows:

1) user1 add's a friend called user2
2) user2 confirms that user1 is his friend

what should happen is user2 and user1 see's each others name in their
friends list. What's happening now is I am able to add user2 to user1
friends list but user1 cannot see user2 in his/her list. My question
is how do I get user1 to show up in user2's list and user2 to show up
in user1's friend list if a user has confirmed friendship? I was
thinking of utilizing the confirmation status in the model and because
that user1 and user2's id is both in the confirmed relationship I
don't see any integrity issues here. Any tips?

Friendship model:

class Friendship(models.Model):
        NOT_CONFIRMED = 1
        PENDING= 2
        CONFIRMED = 3

        STATUS_CHOICES = (
                (NOT_CONFIRMED, 'Not Confirmed'),
                (PENDING, 'Pending'),
                (CONFIRMED, 'Confirmed'),
        )
        from_friend = models.ForeignKey(User, related_name='friend_set')
        to_friend = models.ForeignKey(User, related_name='to_friend_set')
        confirmed = models.IntegerField(choices=STATUS_CHOICES,
default=NOT_CONFIRMED)

        class Meta:
                unique_together = (('to_friend', 'from_friend'),)

        def __unicode__(self):
                return '%s, %s' % (self.from_friend.username,
self.to_friend.username)

Views to render the friendships (as you can see, I have been playing
with the filtering):
@login_required
def friends_list(request, username):
        user = get_object_or_404(User, username=username)
        #friends = [friendship for friendship in user.friend_set.filter(Q
(confirmed=2) | Q(confirmed=3))]
        friends = Friendship.objects.filter(
                Q(to_friend=user) | Q(confirmed=3)
        )

        # get friends latest 10 shows
        friend_shows = Show.objects.filter(user__in=friends).order_by('-id')
        return render_to_response('habit/friends_list.html', {
                'user': request.user,
                'friends': friends,
                'shows': friend_shows[:10],
                'username': username,
        })

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.


Reply via email to