coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.06k stars 1.37k forks source link

TypeError: 'str' object is not callable peewee #2907

Closed xiaojin20 closed 2 months ago

xiaojin20 commented 2 months ago

File "/usr/local/lib/python3.11/dist-packages/robyn/router.py", line 145, in inner_handler handler(*args, kwargs), ^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/www/website.py", line 42, in updatearticle dbapi.updatearticle(1,1,"python sql","标题","updateuser","简介","内容") File "/root/www/dbapi.py", line 19, in updatearticle a.save() File "/usr/local/lib/python3.11/dist-packages/peewee.py", line 6938, in save rows = self.update(field_dict).where(self._pk_expr()).execute() ^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'str' object is not callable

TypeError: 'str' object is not callable?????

文章数据表

class Articles(BaseModel): tid = IntegerField(default=0) title = CharField() author= CharField(default='admin') createt = CharField(default=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) update = CharField(default='0') status = IntegerField(default=0) # 显示控制,或其他 abstr = CharField() content = TextField()

`def updatearticle(aidd,tidd,tagss,titlee,authorr,abstrr,contentt):

print("update_article更新文章,测试")
print(f"文章id:{aidd}")
updatet=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 获取要更新的文章对象
a=Articles.get_or_none(Articles.id==aidd)
if a:
    a.tid = int(tidd)
    a.title = titlee
    a.author = authorr
    a.update = updatet
    a.abstr = abstrr
    a.content = contentt
    a.save()
    print("update_article赋值测试")
else:
    print("更新文章错误!")
# 保存更新后的文章
print(tagss)`
coleifer commented 2 months ago

Bro if you can't even format your code how do you expect me to care enough to investigate...

But the issue is that you are using a field named "a.update". Model.update is a method, so you must not name your fields update (or any of the other methods on Model).