python - Get full result back from PeeWee query (for conversion to JSON) -
i trying render peewee query result json
using following code:
@app.route('/') def index(): c = category.select().order_by(category.name).get() return jsonify(model_to_dict(c))
doing 1 row query. i'm pretty sure issue use of get()
, docs returns 1 row. use in place of get()
fetch entire results back?
this question below pointed me in right direction, is using get()
what use in place of get() fetch entire results back?
modify code be:
query = category.select().order_by(category.name) return jsonify({'rows':[model_to_dict(c) c in query]})
alternatively, do:
query = category.select().order_by(category.name).dicts() return jsonify({'rows':list(query)})
Comments
Post a Comment