0

I have successfully queried a database with MySQL.connector:

search_term = form.searchstring.data
mycursor.execute('''SELECT *
                    FROM post
                    WHERE title like '%'''+search_term+'''%'
                    OR description like '%'''+search_term+'''%'
                    OR priority like '%'''+search_term+'''%'
                    OR date_posted like '%'''+search_term+'''%'
                    OR time_posted like '%'''+search_term+'''%'
                    OR date_closed like '%'''+search_term+'''%'
                    OR time_closed like '%'''+search_term+'''%'
                    OR status like '%'''+search_term+'''%'
                    OR assigned_to like '%'''+search_term+'''%'
                    OR reported_by like '%'''+search_term+'''%'
                    ;''')
res =  mycursor.fetchall()

I am struggling with the flask-sqlalchemy equivalent for the above. I.e...

res = Post.query.########

1 Answer 1

1

Something like this should work:

search_term = "%{}%".format(search_string)
res=Post.query.filter(Post.title.like(search_term) | Post.description.like(search_term) 
 ..go on with all the filters... | Post.reported_to.like(search_term)).all()
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.