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
093febb9
Commit
093febb9
authored
Oct 08, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for relational fields
parent
3fa4a189
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
1 deletions
+8
-1
rest_framework/fields.py
+8
-1
tests/test_relations_hyperlink.py
+0
-0
tests/test_relations_pk.py
+0
-0
tests/test_relations_slug.py
+0
-0
No files found.
rest_framework/fields.py
View file @
093febb9
from
django
import
forms
from
django.conf
import
settings
from
django.core
import
validators
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ObjectDoesNotExist
,
ValidationError
from
django.utils
import
six
,
timezone
from
django.utils.datastructures
import
SortedDict
from
django.utils.dateparse
import
parse_date
,
parse_datetime
,
parse_time
...
...
@@ -54,6 +54,8 @@ def get_attribute(instance, attrs):
for
attr
in
attrs
:
try
:
instance
=
getattr
(
instance
,
attr
)
except
ObjectDoesNotExist
:
return
None
except
AttributeError
as
exc
:
try
:
return
instance
[
attr
]
...
...
@@ -108,6 +110,7 @@ class Field(object):
default_validators
=
[]
default_empty_html
=
empty
initial
=
None
coerce_blank_to_null
=
True
def
__init__
(
self
,
read_only
=
False
,
write_only
=
False
,
required
=
None
,
default
=
empty
,
initial
=
empty
,
source
=
None
,
...
...
@@ -245,6 +248,9 @@ class Field(object):
self
.
fail
(
'required'
)
return
self
.
get_default
()
if
data
==
''
and
self
.
coerce_blank_to_null
:
data
=
None
if
data
is
None
:
if
not
self
.
allow_null
:
self
.
fail
(
'null'
)
...
...
@@ -413,6 +419,7 @@ class CharField(Field):
'blank'
:
_
(
'This field may not be blank.'
)
}
initial
=
''
coerce_blank_to_null
=
False
def
__init__
(
self
,
**
kwargs
):
self
.
allow_blank
=
kwargs
.
pop
(
'allow_blank'
,
False
)
...
...
tests/test_relations_hyperlink.py
View file @
093febb9
This diff is collapsed.
Click to expand it.
tests/test_relations_pk.py
View file @
093febb9
This diff is collapsed.
Click to expand it.
tests/test_relations_slug.py
View file @
093febb9
This diff is collapsed.
Click to expand it.
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