0

I am trying to create variable of users whose ID is in list but i dont know how. This is what I tried but it doesnt work. Does someone know how to filter it correctly?

list = [1, 2, 3, 4]
users = Users.query.filter(Users.id in list)
1
  • Flask uses sqlalchemy by default, so this SQLAlchemy IN clause must answer your question Commented Apr 2, 2022 at 22:20

1 Answer 1

-1

try this instead

list = [1, 2, 3, 4]
all = Users.query.all() # get all users
users = [] # in the end, this list will store the users which have an id in the list

# loop through all the users
for user in all:
  if user.id in list:
    users.append(user) # if the user's id is in list append to list

# you now have a list of users in list stored in the variable users!
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.