How can i create timestamps automatically in my schemas in python?
For example in Javascript you can do something like this
var thingSchema = new Schema({..}, { timestamps: true });
timestamps: true will create created_at and update_at field in my schema and it will also update updated_at field every time i change something in that document How can i achieve this in python
My python schema looks like this
class UserSchema(BaseModel):
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
user_name: str = Field(...)
user_email: EmailStr = Field(...)
class Config:
allow_population_by_field_name = True
arbitrary_types_allowed = True
json_encoders = {ObjectId: str}