0

So I've got different columns, and I'm making a search bar to search for different criteria so a user could narrow their search.

my search command:

def search():
    search=request.args.get('search')
    search='%{}%'.format(search)
    games=Game.query.filter(or_(Game.name.like(search),Game.genre.like(search),Game.platform.like(search)))
    return render_template('ConsoleGames.html', games=games)

My database model:

class Game(db.Model):
    __tablename__='games'
    id=db.Column(db.Integer, primary_key=True)
    name=db.Column(db.String(64), nullable=False)
    genre=db.Column(db.String(64), nullable=False)
    description=db.Column(db.String(300), nullable=False)
    image=db.Column(db.String(60), nullable=False)
    price=db.Column(db.Integer, nullable=False)
    platform=db.Column(db.String(64), nullable=False)
    consoletype_id=db.Column(db.Integer, db.ForeignKey('consoletype.id'))

Currently, I can only search 1 criteria from 1 column at a time. Trying to do both will give me a blank page. How would I make it so that I could search for multiple criteria from different columns?

2
  • Format your code properly using tabs to make it more understandable!! Commented May 31, 2020 at 1:25
  • Does this answer your question? sqlalchemy filter multiple columns Commented May 31, 2020 at 1:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.