I have this function (SQLAlchemy):
# table: Table to search (should be the class name)
# column: filter to use
# search: search term
#
# Returns a list [object] with the found entries in the database
# Uses the SQL LIKE statement
def search(table, column, search):
results = dbsession.query(table).filter(column.like('%' + search + '%')).all()
return results
So this search function searches in the class 'table', uses the filter 'column' and searches for 'search'. The problem I'm having now is that if I enter a value for 'column' (wich is actually not a string but a piece of code) I always get an error that the name doesn't exists:
users = search(User, fname, 'Jo')
NameError: name 'fname' is not defined
Does anybody know how to code this properly?
fname, not a sqlalchemy problem.User.fnameis the column..