from emmett import App, request, response
from emmett.orm import Database, Model, Field
from emmett.tools import service
class TimeTravel(Model):
traveler = Field.string()
returned = Field.bool(default=False)
app = App(__name__)
db = Database(app)
db.define_models(TimeTravel)
app.pipeline = [db.pipe]
@app.route(methods='get')
@service.json
async def completed_travels():
page = request.query_params.page or 1
travels = TimeTravel.where(
lambda t: t.returned == True
).select(paginate=(page, 20))
return {'travels': travels}