def get(cls, _id): try: _id = ObjectId(_id) except Exception: pass # result = DB.read_one(cls.collection, {'_id': ObjectId(_id)}) result = DB.read_one(cls.collection, {'_id': _id}) if result: return cls(result) return None
def read(cls, query, many=False): if many: return [ cls(record) for record in DB.read_many(cls.collection, query) ] else: record = (DB.read_one(cls.collection, query)) if record: return cls(record) return None