當前位置: 首頁>>代碼示例>>Python>>正文


Python mongoengine.ListField方法代碼示例

本文整理匯總了Python中mongoengine.ListField方法的典型用法代碼示例。如果您正苦於以下問題:Python mongoengine.ListField方法的具體用法?Python mongoengine.ListField怎麽用?Python mongoengine.ListField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mongoengine的用法示例。


在下文中一共展示了mongoengine.ListField方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ListField

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [as 別名]
def test_ListField(self):
        class Doc(me.Document):
            list = me.ListField(me.StringField())
        fields_ = fields_for_model(Doc)
        assert type(fields_['list']) is fields.List
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        list_ = ['A', 'B', 'C']
        doc = Doc(list=list_)
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'list': list_}
        load = DocSchema().load(dump.data)
        assert not load.errors
        assert load.data.list == list_ 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:18,代碼來源:test_fields.py

示例2: test_ListSpecialField

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [as 別名]
def test_ListSpecialField(self):
        class NestedDoc(me.EmbeddedDocument):
            field = me.StringField()
        class Doc(me.Document):
            list = me.ListField(me.EmbeddedDocumentField(NestedDoc))
        fields_ = fields_for_model(Doc)
        assert type(fields_['list']) is fields.List
        assert type(fields_['list'].container) is fields.Nested
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        list_ = [{'field': 'A'}, {'field': 'B'}, {'field': 'C'}]
        doc = Doc(list=list_)
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'list': list_}
        load = DocSchema().load(dump.data)
        assert not load.errors
        for i, elem in enumerate(list_):
            assert load.data.list[i].field == elem['field'] 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:22,代碼來源:test_fields.py

示例3: models

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [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

示例4: test_skip_none_field

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [as 別名]
def test_skip_none_field(self):
        class Doc(me.Document):
            field_not_empty = me.StringField(default='value')
            field_empty = me.StringField()
            list_empty = me.ListField(me.StringField())
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        doc = Doc()
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'field_not_empty': 'value'} 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:14,代碼來源:test_skip.py

示例5: test_disable_skip_none_field

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [as 別名]
def test_disable_skip_none_field(self):
        class Doc(me.Document):
            field_empty = me.StringField()
            list_empty = me.ListField(me.StringField())
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
                model_skip_values = ()
        doc = Doc()
        data, errors = DocSchema().dump(doc)
        assert not errors
        assert data == {'field_empty': None, 'list_empty': []} 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:14,代碼來源:test_skip.py

示例6: test_should_field_convert_list

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [as 別名]
def test_should_field_convert_list():
    assert_conversion(
        mongoengine.ListField, graphene.List, field=mongoengine.StringField()
    ) 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:6,代碼來源:test_converter.py

示例7: construct_fields

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import ListField [as 別名]
def construct_fields(model, registry, only_fields, exclude_fields):
    """
    Args:
        model (mongoengine.Document):
        registry (graphene_mongo.registry.Registry):
        only_fields ([str]):
        exclude_fields ([str]):

    Returns:
        (OrderedDict, OrderedDict): converted fields and self reference fields.

    """
    _model_fields = get_model_fields(model)
    fields = OrderedDict()
    self_referenced = OrderedDict()
    for name, field in _model_fields.items():
        is_not_in_only = only_fields and name not in only_fields
        is_excluded = name in exclude_fields
        if is_not_in_only or is_excluded:
            # We skip this field if we specify only_fields and is not
            # in there. Or when we exclude this field in exclude_fields
            continue
        if isinstance(field, mongoengine.ListField):
            if not field.field:
                continue
            # Take care of list of self-reference.
            document_type_obj = field.field.__dict__.get("document_type_obj", None)
            if (
                document_type_obj == model._class_name
                or isinstance(document_type_obj, model)
                or document_type_obj == model
            ):
                self_referenced[name] = field
                continue
        converted = convert_mongoengine_field(field, registry)
        if not converted:
            continue
        fields[name] = converted

    return fields, self_referenced 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:42,代碼來源:types.py


注:本文中的mongoengine.ListField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。