您可以覆盖save方法。
class MyModel(mongoengine.document): creation_date = mongo.DateTimeField() modified_date = mongo.DateTimeField(default=datetime.datetime.now) def save(self, *args, **kwargs): if not self.creation_date: self.creation_date = datetime.datetime.now() self.modified_date = datetime.datetime.now() return super(MyModel, self).save(*args, **kwargs)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)