79690685

Date: 2025-07-04 22:23:16
Score: 0.5
Natty:
Report link

I was able to archive getting Mutual friends for request.user friends that are friends to other users who is not friend to request.user.... Using ManyToManyField (Following)

in Views.py/Template

# Mutual Friends
all_following = request.user.profile.following.values_list('pk', flat=True)
mutual_followers = Profile.objects.filter(pk__in=all_following)


# Template
{% for users in profile_users %}

# List of users
<p>{% users.user %}</p>

# Get mutual friend for each users that is friend to request.user
{% for mutual_friend in mutual_followers %}
{% if mutual_friend in users.following.all %}
<p>{{ mutual_friend.user.username }}</p>
{% endif %}
{% endfor %}

{% endfor %}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user30880337