from schema import db, CustomerTable as GF
db.connect()
#this works
query = GF.update(Priority=88).where(GF.CustomerID==1)
query.execute()
有人可以幫我嗎?上面的代碼在更新 sqlite 資料庫時作業正常。底部沒有。
#this doesn't work and help needed...
#JSON string
customers = '{ "name":"john john", "mobile":12345678, "email":"[email protected]"}'
pycustomers = json.loads(customers)
# print(pycustomers["name"])
for keys in pycustomers:
print("This is the key: ", keys, "\t\tThis is the value: ", pycustomers[keys])
query = GF.update({keys: pycustomers[keys]}).where(GF.Mobile==pycustomers["mobile"])
uj5u.com熱心網友回復:
如果 JSON dict 的所有鍵都對應于模型上的欄位,您可以直接將資料傳入:
customers = '{ "name":"john john", "mobile":12345678, "email":"[email protected]"}'
pycustomers = json.loads(customers)
# print(pycustomers["name"])
nrows = (GF.update(pycustomers)
.where(GF.Mobile==pycustomers["mobile"])
.execute())
可能有幫助的檔案:
- http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.update
- http://docs.peewee-orm.com/en/latest/peewee/querying.html#atomic-updates
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/401093.html
上一篇:如何使用sqlite3中另一個表的__rowid__來更新表
下一篇:與Django模型的表關系
