mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Charfied from_native method returns default instead of None. Updated tests.
This commit is contained in:
parent
98cc821099
commit
1ce1f387b0
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user