peewee update not workong

Viewed 97

I'm trying to update the data in the table, but for some reason nothing comes out, what could this be related to? Here is my code:

async def save_edit_payment_type(callback_query: types.CallbackQuery, state: FSMContext):
    await callback_query.message.edit_reply_markup()
    user_data = await state.get_data()
    callback_data_payment = callback_query.data
    await state.update_data(callback_data_payment=callback_data_payment)
    if callback_data_payment == 'cash':
        await callback_query.message.answer('Выберите тип:', reply_markup=keyboards.additional_data)
        await WaiteEditOrder.waiting_purchase_or_sale_data.set()
    else:
        order = Order.get(id=user_data["index"])
        order.update(
            payment_type=callback_data_payment,
            purchase_or_sale='',
            amount_to_be_paid=0,
        )
        order.save()
        await state.finish()
1 Answers

This is completely incorrect:

order = Order.get(id=user_data["index"])
order.update(
    payment_type=callback_data_payment,
    purchase_or_sale='',
    amount_to_be_paid=0,
)
order.save()

Please consult the documentation for very simple examples of how to update an object, but because it's SO, here's the solution:

order = Order.get(id=user_data["index"])
order.payment_type=callback_data_payment
order.purchase_or_sale=''
order.amount_to_be_paid=0
order.save()

Docs http://docs.peewee-orm.com/en/latest/peewee/quickstart.html#storing-data

Related