[Answered ]-Display post to only user friends

1👍

Try this

def post_list(request):
    
    context = {}
    if request.user.is_authenticated:
        friend_list = FriendList.objects.get(user=request.user )
        friends = friend_list.friends.all()
        context['friends'] = friends
        context['posts'] = Post.objects.filter(username__in=friends).order_by('-date_posted')
    return render(request,'feed/feed.html',context)

UPDATE
show current user posts and current user’s friends posts.

def post_list(request):
    
    context = {}
    if request.user.is_authenticated:
        friend_list = FriendList.objects.get(user=request.user )
        friends = friend_list.friends.all()
        context['friends'] = friends
        context['posts'] = Post.objects.filter(username__in=list(friends) + [request.user,]).order_by('-date_posted')
    return render(request,'feed/feed.html',context)

Leave a comment