Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Flask]filter posts from list
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
Age Doesn't Matter, Your Passion Does
- Shreya Jain

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Flask] How to paginate a list of posts SheeppOSU 2 582 Jun-22-2019, 07:45 PM
Last Post: SheeppOSU
  problem using drop down list to filter table. darktitan 1 664 Mar-27-2019, 09:57 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)