Python Forum

Full Version: [Flask]filter posts from list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to filter through posts from a list of user names. I can't figure it out tough so I need some help. The other solution is removing certain posts from a paginated list of posts that are unfiltered. The filtering looks something like this:
Post.query.filter_by(author=UsernameListToFilterBy).all() #I need to filter through a list
Thanks in advance

def home():
    page = request.args.get('page', 1, type=int)
    postFiltered = []
    for followed in current_user.followingList:
        postFiltered.append(Post.query.filter_by(author=followed).first()) #Here I created a list of posts by followed users
    posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=5) #Here I need to filter from the list or...
    for post in posts.items:
        if User.query.filter_by( in current_user.followingList:
            #remove post from posts

    return render_template('Home.html', posts=posts)

I just made a remove item function in the pagination class and removed a post if it was not being followed by the current user