當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。