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)
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)
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!