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
d64bfef5
Commit
d64bfef5
authored
Oct 23, 2015
by
José Padilla
Committed by
José Padilla
Oct 23, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Map all supported FilePathField options
parent
fa93d790
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
rest_framework/utils/field_mapping.py
+15
-0
tests/test_model_serializer.py
+2
-0
No files found.
rest_framework/utils/field_mapping.py
View file @
d64bfef5
...
@@ -106,6 +106,21 @@ def get_field_kwargs(field_name, model_field):
...
@@ -106,6 +106,21 @@ def get_field_kwargs(field_name, model_field):
isinstance
(
model_field
,
models
.
TextField
)):
isinstance
(
model_field
,
models
.
TextField
)):
kwargs
[
'allow_blank'
]
=
True
kwargs
[
'allow_blank'
]
=
True
if
isinstance
(
model_field
,
models
.
FilePathField
):
kwargs
[
'path'
]
=
model_field
.
path
if
model_field
.
match
is
not
None
:
kwargs
[
'match'
]
=
model_field
.
match
if
model_field
.
recursive
is
not
False
:
kwargs
[
'recursive'
]
=
model_field
.
recursive
if
model_field
.
allow_files
is
not
True
:
kwargs
[
'allow_files'
]
=
model_field
.
allow_files
if
model_field
.
allow_folders
is
not
False
:
kwargs
[
'allow_folders'
]
=
model_field
.
allow_folders
if
model_field
.
choices
:
if
model_field
.
choices
:
# If this model field contains choices, then return early.
# If this model field contains choices, then return early.
# Further keyword arguments are not valid.
# Further keyword arguments are not valid.
...
...
tests/test_model_serializer.py
View file @
d64bfef5
...
@@ -67,6 +67,7 @@ class RegularFieldsModel(models.Model):
...
@@ -67,6 +67,7 @@ class RegularFieldsModel(models.Model):
time_field
=
models
.
TimeField
()
time_field
=
models
.
TimeField
()
url_field
=
models
.
URLField
(
max_length
=
100
)
url_field
=
models
.
URLField
(
max_length
=
100
)
custom_field
=
CustomField
()
custom_field
=
CustomField
()
file_path_field
=
models
.
FilePathField
(
path
=
'/tmp/'
)
def
method
(
self
):
def
method
(
self
):
return
'method'
return
'method'
...
@@ -165,6 +166,7 @@ class TestRegularFieldMappings(TestCase):
...
@@ -165,6 +166,7 @@ class TestRegularFieldMappings(TestCase):
time_field = TimeField()
time_field = TimeField()
url_field = URLField(max_length=100)
url_field = URLField(max_length=100)
custom_field = ModelField(model_field=<tests.test_model_serializer.CustomField: custom_field>)
custom_field = ModelField(model_field=<tests.test_model_serializer.CustomField: custom_field>)
file_path_field = FilePathField(path='/tmp/')
"""
)
"""
)
self
.
assertEqual
(
unicode_repr
(
TestSerializer
()),
expected
)
self
.
assertEqual
(
unicode_repr
(
TestSerializer
()),
expected
)
...
...
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