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
c94b354e
Commit
c94b354e
authored
Oct 16, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3509 from jpadilla/textfield-max-length
Map TextField max_length to CharField
parents
1b4a41cb
a1dad503
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
3 deletions
+5
-3
rest_framework/utils/field_mapping.py
+2
-1
tests/test_model_serializer.py
+3
-2
No files found.
rest_framework/utils/field_mapping.py
View file @
c94b354e
...
@@ -123,7 +123,8 @@ def get_field_kwargs(field_name, model_field):
...
@@ -123,7 +123,8 @@ def get_field_kwargs(field_name, model_field):
# Ensure that max_length is passed explicitly as a keyword arg,
# Ensure that max_length is passed explicitly as a keyword arg,
# rather than as a validator.
# rather than as a validator.
max_length
=
getattr
(
model_field
,
'max_length'
,
None
)
max_length
=
getattr
(
model_field
,
'max_length'
,
None
)
if
max_length
is
not
None
and
isinstance
(
model_field
,
models
.
CharField
):
if
max_length
is
not
None
and
(
isinstance
(
model_field
,
models
.
CharField
)
or
isinstance
(
model_field
,
models
.
TextField
)):
kwargs
[
'max_length'
]
=
max_length
kwargs
[
'max_length'
]
=
max_length
validator_kwarg
=
[
validator_kwarg
=
[
validator
for
validator
in
validator_kwarg
validator
for
validator
in
validator_kwarg
...
...
tests/test_model_serializer.py
View file @
c94b354e
...
@@ -63,7 +63,7 @@ class RegularFieldsModel(models.Model):
...
@@ -63,7 +63,7 @@ class RegularFieldsModel(models.Model):
positive_small_integer_field
=
models
.
PositiveSmallIntegerField
()
positive_small_integer_field
=
models
.
PositiveSmallIntegerField
()
slug_field
=
models
.
SlugField
(
max_length
=
100
)
slug_field
=
models
.
SlugField
(
max_length
=
100
)
small_integer_field
=
models
.
SmallIntegerField
()
small_integer_field
=
models
.
SmallIntegerField
()
text_field
=
models
.
TextField
()
text_field
=
models
.
TextField
(
max_length
=
100
)
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
()
...
@@ -161,11 +161,12 @@ class TestRegularFieldMappings(TestCase):
...
@@ -161,11 +161,12 @@ class TestRegularFieldMappings(TestCase):
positive_small_integer_field = IntegerField()
positive_small_integer_field = IntegerField()
slug_field = SlugField(max_length=100)
slug_field = SlugField(max_length=100)
small_integer_field = IntegerField()
small_integer_field = IntegerField()
text_field = CharField(style={'base_template': 'textarea.html'})
text_field = CharField(
max_length=100,
style={'base_template': 'textarea.html'})
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>)
"""
)
"""
)
self
.
assertEqual
(
unicode_repr
(
TestSerializer
()),
expected
)
self
.
assertEqual
(
unicode_repr
(
TestSerializer
()),
expected
)
def
test_field_options
(
self
):
def
test_field_options
(
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