本文整理汇总了Python中django.contrib.postgres.forms.JSONField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.JSONField方法的具体用法?Python forms.JSONField怎么用?Python forms.JSONField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.postgres.forms
的用法示例。
在下文中一共展示了forms.JSONField方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_transform
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def get_transform(self, name):
transform = super(JSONField, self).get_transform(name)
if transform:
return transform
return KeyTransformFactory(name)
示例2: get_prep_lookup
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def get_prep_lookup(self, lookup_type, value):
if lookup_type in ('has_key', 'has_keys', 'has_any_keys'):
return value
if isinstance(value, (dict, list)):
return Json(value)
return super(JSONField, self).get_prep_lookup(lookup_type, value)
示例3: validate
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def validate(self, value, model_instance):
super(JSONField, self).validate(value, model_instance)
try:
json.dumps(value)
except TypeError:
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)
示例4: formfield
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def formfield(self, **kwargs):
defaults = {'form_class': forms.JSONField}
defaults.update(kwargs)
return super(JSONField, self).formfield(**defaults)
示例5: __init__
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def __init__(self, verbose_name=None, name=None, encoder=None, **kwargs):
if encoder and not callable(encoder):
raise ValueError("The encoder parameter must be a callable object.")
self.encoder = encoder
super(JSONField, self).__init__(verbose_name, name, **kwargs)
示例6: deconstruct
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(JSONField, self).deconstruct()
if self.encoder is not None:
kwargs['encoder'] = self.encoder
return name, path, args, kwargs
示例7: validate
# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import JSONField [as 别名]
def validate(self, value, model_instance):
super(JSONField, self).validate(value, model_instance)
options = {'cls': self.encoder} if self.encoder else {}
try:
json.dumps(value, **options)
except TypeError:
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)