当前位置: 首页>>代码示例>>Python>>正文


Python mongoengine.DictField方法代码示例

本文整理汇总了Python中mongoengine.DictField方法的典型用法代码示例。如果您正苦于以下问题:Python mongoengine.DictField方法的具体用法?Python mongoengine.DictField怎么用?Python mongoengine.DictField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongoengine的用法示例。


在下文中一共展示了mongoengine.DictField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_DictField

# 需要导入模块: import mongoengine [as 别名]
# 或者: from mongoengine import DictField [as 别名]
def test_DictField(self):
        class Doc(me.Document):
            data = me.DictField()
        fields_ = fields_for_model(Doc)
        assert type(fields_['data']) is fields.Raw
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        data = {
            'int_1': 1,
            'nested_2': {
                'sub_int_1': 42,
                'sub_list_2': []
            },
            'list_3': ['a', 'b', 'c']
        }
        doc = Doc(data=data)
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'data': data}
        load = DocSchema().load(dump.data)
        assert not load.errors
        assert load.data.data == data 
开发者ID:touilleMan,项目名称:marshmallow-mongoengine,代码行数:25,代码来源:test_fields.py

示例2: models

# 需要导入模块: import mongoengine [as 别名]
# 或者: from mongoengine import DictField [as 别名]
def models():

    class HeadTeacher(me.EmbeddedDocument):
        full_name = me.StringField(max_length=255, unique=True, default='noname')

    class Course(me.Document):
        id = me.IntField(primary_key=True)
        name = me.StringField()
        # These are for better model form testing
        cost = me.IntField()
        description = me.StringField()
        level = me.StringField(choices=('Primary', 'Secondary'))
        prereqs = me.DictField()
        started = me.DateTimeField()
        grade = AnotherIntegerField()
        students = me.ListField(me.ReferenceField('Student'))

    class School(me.Document):
        name = me.StringField()
        students = me.ListField(me.ReferenceField('Student'))
        headteacher = me.EmbeddedDocumentField(HeadTeacher)

    class Student(me.Document):
        full_name = me.StringField(max_length=255, unique=True, default='noname')
        age = me.IntField(min_value=10, max_value=99)
        dob = me.DateTimeField(null=True)
        date_created = me.DateTimeField(default=dt.datetime.utcnow,
                                        help_text='date the student was created')
        current_school = me.ReferenceField('School')
        courses = me.ListField(me.ReferenceField('Course'))
        email = me.EmailField(max_length=100)
        profile_uri = me.URLField(max_length=200)

    # So that we can access models with dot-notation, e.g. models.Course
    class _models(object):

        def __init__(self):
            self.HeadTeacher = HeadTeacher
            self.Course = Course
            self.School = School
            self.Student = Student
    return _models() 
开发者ID:touilleMan,项目名称:marshmallow-mongoengine,代码行数:44,代码来源:test_marshmallow_mongoengine.py

示例3: test_should_dict_convert_json

# 需要导入模块: import mongoengine [as 别名]
# 或者: from mongoengine import DictField [as 别名]
def test_should_dict_convert_json():
    assert_conversion(mongoengine.DictField, graphene.JSONString) 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:4,代码来源:test_converter.py

示例4: validate

# 需要导入模块: import mongoengine [as 别名]
# 或者: from mongoengine import DictField [as 别名]
def validate(self, value):
        if not isinstance(value, dict):
            self.error('Only dictionaries may be used in a DictField')
        if me.fields.key_not_string(value):
            self.error("Invalid dictionary key - documents must have only string keys")
        me.base.ComplexBaseField.validate(self, value) 
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:stormbase.py


注:本文中的mongoengine.DictField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。