Last active
March 20, 2020 13:59
-
-
Save nguyenbathanh/d5014f5568699ba111b2f0eb067eada8 to your computer and use it in GitHub Desktop.
Revisions
-
nguyenbathanh revised this gist
Oct 31, 2018 . No changes.There are no files selected for viewing
-
nguyenbathanh renamed this gist
Oct 31, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
nguyenbathanh created this gist
Oct 31, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import datetime import json from bson import ObjectId from mongoengine.base import BaseDocument from mongoengine.queryset import QuerySet class MongoengineEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, BaseDocument): return obj.to_mongo() if isinstance(obj, QuerySet): return list(obj) if isinstance(obj, ObjectId): return str(obj) if isinstance(obj, datetime.datetime): return obj.isoformat() return json.JSONEncoder.default(self, obj)