fields.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码
def to_mongo(self, document, use_db_field=True, fields=None):
        id_field_name = self.document_type._meta['id_field']
        id_field = self.document_type._fields[id_field_name]

        if isinstance(document, Document):
            # We need the id from the saved object to create the DBRef
            id_ = document.pk
            if id_ is None:
                self.error('You can only reference documents once they have'
                           ' been saved to the database')
        else:
            self.error('Only accept a document object')
            # TODO: should raise here or will fail next statement

        value = SON((
            ('_id', id_field.to_mongo(id_)),
        ))

        if fields:
            new_fields = [f for f in self.fields if f in fields]
        else:
            new_fields = self.fields

        value.update(dict(document.to_mongo(use_db_field, fields=new_fields)))
        return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号