예제 #1
0
파일: fields.py 프로젝트: ezekial4/mongodm
 def from_dict(self, object, datas):
     """ hydrating collection from dict """
     list = []
     if isinstance(self._allowed, str):
         self._allowed = get_document_class(self._allowed)
     for document in datas:
         list.append(self._allowed(datas=document._datas))
     setattr(object, self.name, list)
예제 #2
0
파일: fields.py 프로젝트: ezekial4/mongodm
 def __get__(self, instance, owner):
     """ foreign getter """
     if isinstance(self._allowed, str):
         self._allowed = get_document_class(self._allowed)
     db = self._allowed.__db__
     if instance is None:
         return self
     else:
         if instance._datas and instance._datas[self.name].__class__ == self._allowed:
             return instance._datas[self.name]
         elif instance._datas[self.name] != None:
             return self._allowed(_id=instance._datas[self.name].id, datas=db.dereference(instance._datas[self.name]))
예제 #3
0
파일: fields.py 프로젝트: ezekial4/mongodm
 def from_dict(self, object, datas):
     """ hydrating embedded document from dict """
     if isinstance(self._allowed, str):
         self._allowed = get_document_class(self._allowed)
     embedded = self._allowed(datas=datas._datas)
     setattr(object, self.name, embedded)