本文整理汇总了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',
)
])
示例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(), [])
示例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.')
示例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})
示例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'})
示例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')
示例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'})
示例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})
示例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, {})
示例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)