Charfied from_native method returns default instead of None. Updated tests.

This commit is contained in:
Serhiy Voyt 2014-05-06 21:57:25 +03:00
parent 98cc821099
commit 1ce1f387b0
3 changed files with 12 additions and 2 deletions

View File

@ -469,8 +469,15 @@ class CharField(WritableField):
self.validators.append(validators.MaxLengthValidator(max_length))
def from_native(self, value):
if isinstance(value, six.string_types) or value is None:
if isinstance(value, six.string_types):
return value
if value is None:
if self.default:
return self.default
else:
value
return smart_text(value)

View File

@ -105,6 +105,7 @@ class Album(RESTFrameworkModel):
title = models.CharField(max_length=100, unique=True)
ref = models.CharField(max_length=10, unique=True, null=True, blank=True)
class Photo(RESTFrameworkModel):
description = models.TextField()
album = models.ForeignKey(Album)
@ -112,7 +113,8 @@ class Photo(RESTFrameworkModel):
# Model for issue #324
class BlankFieldModel(RESTFrameworkModel):
title = models.CharField(max_length=100, blank=True, null=False)
title = models.CharField(max_length=100, blank=True, null=False,
default="title")
# Model for issue #380

View File

@ -1238,6 +1238,7 @@ class BlankFieldTests(TestCase):
self.assertEqual(serializer.is_valid(), True)
serializer.save()
self.assertTrue(serializer.object.pk is not None)
self.assertEqual(serializer.object.title, 'title')
def test_create_not_blank_field(self):
"""