Reputation: 8277
I have created model class inherititng form 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'))
but when I insert new value for just only id field to the example
table I do not get the default text
value as "waiting" and date_added also comes out to be 0000-00-00 00:00:00
isntead of current date time.
Upvotes: 1
Views: 1051
Reputation: 26245
The fields need to be members of the class:
class Example(peewee.Model):
id = peewee.IntField(primary_key=True)
text = peewee.CharField(default="waiting")
dt = peewee.DateTimeField(default=datetime.datetime.now)
Additionally, you want the default value to be a callable for the datetime...otherwise it will evaluate datetime.datetime.now() at the time the module is loaded and never re-evaluate it.
Upvotes: 2