我已经创建了模型类inherititng表单peewee.Model。
import peewee
class Example(peewee.Model):
id = peewee.IntField(primary_key=True)
text = peewee.charField(default="waiting")
dt = peewee.DateTimeField(default=datetime.datetime.now().strftime('%Y-%m-%d'))但是,当我仅将id字段的新值插入到example表中时,就不会得到默认的text值,即“等待”,而date_added也是当前日期时间的0000-00-00 00:00:00 isntead。
发布于 2018-05-02 14:38:46
字段必须是类的成员:
class Example(peewee.Model):
id = peewee.IntField(primary_key=True)
text = peewee.CharField(default="waiting")
dt = peewee.DateTimeField(default=datetime.datetime.now)此外,您希望datetime...otherwise的默认值是可调用的,它将在加载模块时计算datetime.datetime.now(),并且永远不会重新计算它。
https://stackoverflow.com/questions/50126823
复制相似问题