Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, time
- from mongoengine import StringField, DateField, Document
- from utils import db
- def convert_date(py_date):
- """Function that converts `datetime.date` object to `datetime.datetime` object.
- Needed in order to persist using `mongoengine` to Atlas, as `mongoengine` is unable to automatically convert `datetime.date` to a MongoDB-compatible format.
- """
- return datetime.combine(py_date, time=time.min)
- # Create your models here.
- class React(Document):
- url = StringField(max_length = 300)
- date = DateField()
- def save(self, *args, **kwargs):
- db.vlad_collection.insert_one({
- '_id': self.url,
- 'date': convert_date(self.date),
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement