I am trying to gather the values of a column from table. I used SQLAlchemy to get all the objects, and then I do a loop to get all the results for a specific column - column_name. However, I get the column name from the client (browser), so it comes in as a string. As a results, I get the error: AttributeError: 'DataTable' object has no attribute 'column_name'. How do I convert the value of column_name into the correct type?
def chart_data():
column_name = request.args.get('id')
person_id = 1
results = DataTable.query.filter_by(person_id = person_id).all()
alist = []
for x in results:
alist.append(float(round(x.column_name, 4)))
return jsonify({"results" : alist})