Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
8eadac39
Commit
8eadac39
authored
Jun 27, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1665 from smal/modelserialization-charfield-with-null
Modelserialization charfield with null
parents
636ae419
3326ddc8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
2 deletions
+11
-2
rest_framework/fields.py
+5
-1
rest_framework/tests/models.py
+3
-1
rest_framework/tests/test_serializer.py
+3
-0
No files found.
rest_framework/fields.py
View file @
8eadac39
...
@@ -474,8 +474,12 @@ class CharField(WritableField):
...
@@ -474,8 +474,12 @@ class CharField(WritableField):
self
.
validators
.
append
(
validators
.
MaxLengthValidator
(
max_length
))
self
.
validators
.
append
(
validators
.
MaxLengthValidator
(
max_length
))
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
if
isinstance
(
value
,
six
.
string_types
)
or
value
is
None
:
if
isinstance
(
value
,
six
.
string_types
):
return
value
return
value
if
value
is
None
:
return
''
return
smart_text
(
value
)
return
smart_text
(
value
)
...
...
rest_framework/tests/models.py
View file @
8eadac39
...
@@ -105,6 +105,7 @@ class Album(RESTFrameworkModel):
...
@@ -105,6 +105,7 @@ class Album(RESTFrameworkModel):
title
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
title
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
ref
=
models
.
CharField
(
max_length
=
10
,
unique
=
True
,
null
=
True
,
blank
=
True
)
ref
=
models
.
CharField
(
max_length
=
10
,
unique
=
True
,
null
=
True
,
blank
=
True
)
class
Photo
(
RESTFrameworkModel
):
class
Photo
(
RESTFrameworkModel
):
description
=
models
.
TextField
()
description
=
models
.
TextField
()
album
=
models
.
ForeignKey
(
Album
)
album
=
models
.
ForeignKey
(
Album
)
...
@@ -112,7 +113,8 @@ class Photo(RESTFrameworkModel):
...
@@ -112,7 +113,8 @@ class Photo(RESTFrameworkModel):
# Model for issue #324
# Model for issue #324
class
BlankFieldModel
(
RESTFrameworkModel
):
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
# Model for issue #380
...
...
rest_framework/tests/test_serializer.py
View file @
8eadac39
...
@@ -1236,6 +1236,9 @@ class BlankFieldTests(TestCase):
...
@@ -1236,6 +1236,9 @@ class BlankFieldTests(TestCase):
def
test_create_model_null_field
(
self
):
def
test_create_model_null_field
(
self
):
serializer
=
self
.
model_serializer_class
(
data
=
{
'title'
:
None
})
serializer
=
self
.
model_serializer_class
(
data
=
{
'title'
:
None
})
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
serializer
.
save
()
self
.
assertIsNot
(
serializer
.
object
.
pk
,
None
)
self
.
assertEqual
(
serializer
.
object
.
title
,
''
)
def
test_create_not_blank_field
(
self
):
def
test_create_not_blank_field
(
self
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment