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
1ce1f387
Commit
1ce1f387
authored
May 06, 2014
by
Serhiy Voyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Charfied from_native method returns default instead of None. Updated tests.
parent
98cc8210
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
2 deletions
+12
-2
rest_framework/fields.py
+8
-1
rest_framework/tests/models.py
+3
-1
rest_framework/tests/test_serializer.py
+1
-0
No files found.
rest_framework/fields.py
View file @
1ce1f387
...
@@ -469,8 +469,15 @@ class CharField(WritableField):
...
@@ -469,8 +469,15 @@ 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
:
if
self
.
default
:
return
self
.
default
else
:
value
return
smart_text
(
value
)
return
smart_text
(
value
)
...
...
rest_framework/tests/models.py
View file @
1ce1f387
...
@@ -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 @
1ce1f387
...
@@ -1238,6 +1238,7 @@ class BlankFieldTests(TestCase):
...
@@ -1238,6 +1238,7 @@ class BlankFieldTests(TestCase):
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
self
.
assertEqual
(
serializer
.
is_valid
(),
True
)
serializer
.
save
()
serializer
.
save
()
self
.
assertTrue
(
serializer
.
object
.
pk
is
not
None
)
self
.
assertTrue
(
serializer
.
object
.
pk
is
not
None
)
self
.
assertEqual
(
serializer
.
object
.
title
,
'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