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


Python fields.HStoreField方法代码示例

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


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

示例1: test_invalid_default

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

        model = MyModel()
        self.assertEqual(model.check(), [
            checks.Warning(
                msg=(
                    "HStoreField 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 `dict` instead of `{}`.',
                obj=MyModel._meta.get_field('field'),
                id='postgres.E003',
            )
        ]) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:test_hstore.py

示例2: test_valid_default

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

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

示例3: test_not_a_string

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_not_a_string(self):
        field = HStoreField()
        with self.assertRaises(exceptions.ValidationError) as cm:
            field.clean({'a': 1}, None)
        self.assertEqual(cm.exception.code, 'not_a_string')
        self.assertEqual(cm.exception.message % cm.exception.params, 'The value of "a" is not a string or null.') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_hstore.py

示例4: test_none_allowed_as_value

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_none_allowed_as_value(self):
        field = HStoreField()
        self.assertEqual(field.clean({'a': None}, None), {'a': None}) 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_hstore.py

示例5: test_valid

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_valid(self):
        field = forms.HStoreField()
        value = field.clean('{"a": "b"}')
        self.assertEqual(value, {'a': 'b'}) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_hstore.py

示例6: test_non_dict_json

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_non_dict_json(self):
        field = forms.HStoreField()
        msg = 'Input must be a JSON dictionary.'
        with self.assertRaisesMessage(exceptions.ValidationError, msg) as cm:
            field.clean('["a", "b", 1]')
        self.assertEqual(cm.exception.code, 'invalid_format') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_hstore.py

示例7: test_not_string_values

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_not_string_values(self):
        field = forms.HStoreField()
        value = field.clean('{"a": 1}')
        self.assertEqual(value, {'a': '1'}) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_hstore.py

示例8: test_none_value

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_none_value(self):
        field = forms.HStoreField()
        value = field.clean('{"a": null}')
        self.assertEqual(value, {'a': None}) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_hstore.py

示例9: test_empty

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_empty(self):
        field = forms.HStoreField(required=False)
        value = field.clean('')
        self.assertEqual(value, {}) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_hstore.py

示例10: test_model_field_formfield

# 需要导入模块: from django.contrib.postgres import fields [as 别名]
# 或者: from django.contrib.postgres.fields import HStoreField [as 别名]
def test_model_field_formfield(self):
        model_field = HStoreField()
        form_field = model_field.formfield()
        self.assertIsInstance(form_field, forms.HStoreField) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_hstore.py


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