Mongoengine creation_time attribute in Document

后端 未结 9 1326
Happy的楠姐
Happy的楠姐 2020-12-14 15:50

I am trying to add a creation_time attribute to my documents. The following would be an example:

import datetime

class MyModel(mongoengine.Docu         


        
9条回答
  •  失恋的感觉
    2020-12-14 15:58

    My preferred solution is to use the @property decorator to return the creation datetime as extracted from the ObjectId:

    @property
    def creation_stamp(self):
        return self.id.generation_time
    

提交回复
热议问题