def default(self, obj): if isinstance(obj, QuerySet): return list(obj) if isinstance(obj, DBRef): doc = get_db().dereference(obj) try: doc.pop('_cls') doc.pop('_types') except: pass return doc if isinstance(obj, (Document, EmbeddedDocument)): doc = obj.to_mongo() try: doc.pop('_cls') doc.pop('_types') except: pass return doc if isinstance(obj, ObjectId): return str(obj) elif isinstance(obj, datetime): return obj.isoformat().replace('T', ' ') elif isinstance(obj, (date, time)): return obj.isoformat() return JSONEncoder.default(self, obj)
def default(self, o): if isinstance(o, datetime.datetime): return o.strftime('%Y-%m-%d %H:%M:%S') elif isinstance(o, datetime.date): return o.strftime('%Y-%m-%d') else: return JSONEncoder.default(self, o)
def default(self, o): if isinstance(o, Packet) or hasattr(o, 'serialized'): return o.serialized return JSONEncoder.default(self, o)