如何执行插入查询并返回新行的主键

时间:2013-10-05 00:15:47

标签: python mysql flask peewee

我尝试了flask-peewee / peewee示例。查询成功运行但它不返回新行PK。

这是我的代码:

@app.route('/api/merchant/invoice/',  methods=['POST'])
def merchantInvoice():
    if request.method == 'POST' and request.form['checkin_id']:
        active = checkin_details.select().where(checkin_details.is_active==True)
        try:
            checkin = active.where(checkin_details.id == request.form['checkin_id']).get()
            sale=Sales(
                checkin_id=checkin.id,
                merchant_id =checkin.merchant_id,
                created_at=datetime.datetime.now(),
                sale_amount=request.form['amount'],
                user_id=checkin.user_id
            )
            sale.save()
            return sale_id=sale.id

0 个答案:

没有答案