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()

peewee model json

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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -