Using SQL Alchemy in python to obtain x most recent items
up vote
-2
down vote
favorite
I am trying to make a nested list RECENT_STORES of the x most recently ordered from stores that has their name from the table store and time_ordered from the table shipment . They are connected via shipment.store_id and store.id How do I write a sqlalchemy query (db.session.query...) so that I do the following in order (in psuedocode): get most recent shipment by time_ordered if shipment.store_id not in RECENT_STORES : append store.name and shipment.time_ordered to RECENT_STORES at index x where shipment.store_id == store.id else: get next most recent shipment by time_ordered and repeat the same checks
python python-2.7 sqlalchemy
share | improve this question