[1.1.X] Fixed #13171 -- Corrected the field_subclassing unit test. Thanks to Gabriel Hurley for the report and patch.
Backport of r12838 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12839 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
752856530f
commit
6e60c8b7c0
|
@ -48,23 +48,23 @@ class SmallField(models.Field):
|
||||||
return [force_unicode(v) for v in value]
|
return [force_unicode(v) for v in value]
|
||||||
if lookup_type == 'isnull':
|
if lookup_type == 'isnull':
|
||||||
return []
|
return []
|
||||||
raise FieldError('Invalid lookup type: %r' % lookup_type)
|
raise TypeError('Invalid lookup type: %r' % lookup_type)
|
||||||
|
|
||||||
|
|
||||||
class JSONField(models.TextField):
|
class JSONField(models.TextField):
|
||||||
__metaclass__ = models.SubfieldBase
|
__metaclass__ = models.SubfieldBase
|
||||||
|
|
||||||
description = ("JSONField automatically serializes and desializes values to "
|
description = ("JSONField automatically serializes and desializes values to "
|
||||||
"and from JSON.")
|
"and from JSON.")
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
value = json.loads(value)
|
value = json.loads(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -51,7 +51,7 @@ True
|
||||||
>>> MyModel.objects.filter(data__lt=s)
|
>>> MyModel.objects.filter(data__lt=s)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
FieldError: Invalid lookup type: 'lt'
|
TypeError: Invalid lookup type: 'lt'
|
||||||
|
|
||||||
# Serialization works, too.
|
# Serialization works, too.
|
||||||
>>> stream = serializers.serialize("json", MyModel.objects.all())
|
>>> stream = serializers.serialize("json", MyModel.objects.all())
|
||||||
|
|
Loading…
Reference in New Issue