Search code examples
pythonpython-3.xpeewee

How to get first element Peewee?


There is query:

r = Products.select().where(Products.sku == article)

I tried to get first element like:

print (oldRow.first())

Also tried: print (oldRow[0])

I have got an error:

Error has occurred: Cannot convert b'7115.0000' to Decimal

Solution

  • I think this may be an instance of the same error you posted about (a similar question). Try this patch:

    https://github.com/coleifer/peewee/commit/cd07f4e01a1262166d8944736e11d0681fb76214

    Also, Peewee model instances are not subscriptable. You should access the element using oldRow.price -- not oldRow[0]. The object returned by a query are model instances unless you explicitly tell peewee to return tuples/dicts/namedtuples.

    http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.tuples