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:
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
Post.query.filter_by(author=UsernameListToFilterBy).all() #I need to filter through a listThanks 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(username=post.author.username) in current_user.followingList: #Code else: #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