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


Python fields.ArrayField方法代码示例

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


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

示例1: test_invalid_default

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_invalid_default(self):
        class MyModel(PostgreSQLModel):
            field = ArrayField(models.IntegerField(), default=[])

        model = MyModel()
        self.assertEqual(model.check(), [
            checks.Warning(
                msg=(
                    "ArrayField default should be a callable instead of an "
                    "instance so that it's not shared between all field "
                    "instances."
                ),
                hint='Use a callable instead, e.g., use `list` instead of `[]`.',
                obj=MyModel._meta.get_field('field'),
                id='postgres.E003',
            )
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:test_array.py

示例2: get_field_set_type

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def get_field_set_type(self, api: TypeChecker, field: Union[Field, ForeignObjectRel], *, method: str) -> MypyType:
        """ Get a type of __set__ for this specific Django field. """
        target_field = field
        if isinstance(field, ForeignKey):
            target_field = field.target_field

        field_info = helpers.lookup_class_typeinfo(api, target_field.__class__)
        if field_info is None:
            return AnyType(TypeOfAny.from_error)

        field_set_type = helpers.get_private_descriptor_type(field_info, '_pyi_private_set_type',
                                                             is_nullable=self.get_field_nullability(field, method))
        if isinstance(target_field, ArrayField):
            argument_field_type = self.get_field_set_type(api, target_field.base_field, method=method)
            field_set_type = helpers.convert_any_to_type(field_set_type, argument_field_type)
        return field_set_type 
开发者ID:typeddjango,项目名称:django-stubs,代码行数:18,代码来源:context.py

示例3: label_timing

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def label_timing(request, project_pk):
    """This function finds and returns the requested label time metrics. This is
    used by the graphs on the admin page to show how long each labeler is taking.

    Args:
        request: The POST request
        project_pk: Primary key of the project
    Returns:
        a dictionary of label timing information.
    """
    project = Project.objects.get(pk=project_pk)

    users = []
    users.append(project.creator)
    users.extend([perm.profile for perm in project.projectpermissions_set.all()])

    dataset = []
    yDomain = 0
    for u in users:
        result = DataLabel.objects.filter(data__project=project_pk, profile=u)\
            .aggregate(quartiles=Percentile('time_to_label', [0.05, 0.25, 0.5, 0.75, 0.95],
                                            continuous=False,
                                            output_field=ArrayField(FloatField())))

        if result['quartiles']:
            if result['quartiles'][4] > yDomain:
                yDomain = result['quartiles'][4] + 10
            temp = {
                'label': u.__str__(),
                'values': {
                    'Q1': result['quartiles'][1],
                    'Q2': result['quartiles'][2],
                    'Q3': result['quartiles'][3],
                    'whisker_low': result['quartiles'][0],
                    'whisker_high': result['quartiles'][4]
                }
            }
            dataset.append(temp)

    return Response({'data': dataset, 'yDomain': yDomain}) 
开发者ID:RTIInternational,项目名称:SMART,代码行数:42,代码来源:api_admin.py

示例4: output_field

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def output_field(self):
        return ArrayField(self.source_expressions[0].output_field) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:4,代码来源:general.py

示例5: stringify

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def stringify(cls, field, value=None):
        value = value
        field_class = field.__class__

        if field_class in cls.custom_stringify_methods:
            stringifier = cls.custom_stringify_methods[field_class]

            if isinstance(stringifier, six.string_types):
                stringifier = getattr(cls, stringifier)

            return stringifier(value, field)

        if value is None:
            return None

        if isinstance(field, IntegerField):
            value = int(value)

        if isinstance(field, ArrayField):
            return force_text(', '.join(value))

        if getattr(field, 'choices', None):
            try:
                choices_dict = dict(field.choices)
                value = choices_dict[value]
                return force_text(value)
            except (KeyError, TypeError):
                return force_text(value)

        return force_text(value) 
开发者ID:TriplePoint-Software,项目名称:django_audit_trail,代码行数:32,代码来源:stringifier.py

示例6: test_icontains

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_icontains(self):
        # Using the __icontains lookup with ArrayField is inefficient.
        instance = CharArrayModel.objects.create(field=['FoO'])
        self.assertSequenceEqual(
            CharArrayModel.objects.filter(field__icontains='foo'),
            [instance]
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_array.py

示例7: test_unsupported_lookup

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_unsupported_lookup(self):
        msg = "Unsupported lookup '0_bar' for ArrayField or join on the field not permitted."
        with self.assertRaisesMessage(FieldError, msg):
            list(NullableIntegerArrayModel.objects.filter(field__0_bar=[2]))

        msg = "Unsupported lookup '0bar' for ArrayField or join on the field not permitted."
        with self.assertRaisesMessage(FieldError, msg):
            list(NullableIntegerArrayModel.objects.filter(field__0bar=[2])) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_array.py

示例8: test_field_checks

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_field_checks(self):
        class MyModel(PostgreSQLModel):
            field = ArrayField(models.CharField())

        model = MyModel()
        errors = model.check()
        self.assertEqual(len(errors), 1)
        # The inner CharField is missing a max_length.
        self.assertEqual(errors[0].id, 'postgres.E001')
        self.assertIn('max_length', errors[0].msg) 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_array.py

示例9: test_invalid_base_fields

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_invalid_base_fields(self):
        class MyModel(PostgreSQLModel):
            field = ArrayField(models.ManyToManyField('postgres_tests.IntegerArrayModel'))

        model = MyModel()
        errors = model.check()
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].id, 'postgres.E002') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_array.py

示例10: test_valid_default_none

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_valid_default_none(self):
        class MyModel(PostgreSQLModel):
            field = ArrayField(models.IntegerField(), default=None)

        model = MyModel()
        self.assertEqual(model.check(), []) 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_array.py

示例11: test_nested_field_checks

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_nested_field_checks(self):
        """
        Nested ArrayFields are permitted.
        """
        class MyModel(PostgreSQLModel):
            field = ArrayField(ArrayField(models.CharField()))

        model = MyModel()
        errors = model.check()
        self.assertEqual(len(errors), 1)
        # The inner CharField is missing a max_length.
        self.assertEqual(errors[0].id, 'postgres.E001')
        self.assertIn('max_length', errors[0].msg) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:test_array.py

示例12: test_deconstruct

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_deconstruct(self):
        field = ArrayField(models.IntegerField())
        name, path, args, kwargs = field.deconstruct()
        new = ArrayField(*args, **kwargs)
        self.assertEqual(type(new.base_field), type(field.base_field))
        self.assertIsNot(new.base_field, field.base_field) 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_array.py

示例13: test_deconstruct_with_size

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_deconstruct_with_size(self):
        field = ArrayField(models.IntegerField(), size=3)
        name, path, args, kwargs = field.deconstruct()
        new = ArrayField(*args, **kwargs)
        self.assertEqual(new.size, field.size) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_array.py

示例14: test_deconstruct_args

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_deconstruct_args(self):
        field = ArrayField(models.CharField(max_length=20))
        name, path, args, kwargs = field.deconstruct()
        new = ArrayField(*args, **kwargs)
        self.assertEqual(new.base_field.max_length, field.base_field.max_length) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_array.py

示例15: test_adding_arrayfield_with_index

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import ArrayField [as 别名]
def test_adding_arrayfield_with_index(self):
        """
        ArrayField shouldn't have varchar_patterns_ops or text_patterns_ops indexes.
        """
        table_name = 'postgres_tests_chartextarrayindexmodel'
        call_command('migrate', 'postgres_tests', verbosity=0)
        with connection.cursor() as cursor:
            like_constraint_columns_list = [
                v['columns']
                for k, v in list(connection.introspection.get_constraints(cursor, table_name).items())
                if k.endswith('_like')
            ]
        # Only the CharField should have a LIKE index.
        self.assertEqual(like_constraint_columns_list, [['char2']])
        # All fields should have regular indexes.
        with connection.cursor() as cursor:
            indexes = [
                c['columns'][0]
                for c in connection.introspection.get_constraints(cursor, table_name).values()
                if c['index'] and len(c['columns']) == 1
            ]
        self.assertIn('char', indexes)
        self.assertIn('char2', indexes)
        self.assertIn('text', indexes)
        call_command('migrate', 'postgres_tests', 'zero', verbosity=0)
        with connection.cursor() as cursor:
            self.assertNotIn(table_name, connection.introspection.table_names(cursor)) 
开发者ID:nesdis,项目名称:djongo,代码行数:29,代码来源:test_array.py


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