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
46b31331
Commit
46b31331
authored
Dec 19, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #510 from joual/master
Fixes #509
parents
c29b08ad
262d9c24
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
2 deletions
+17
-2
rest_framework/fields.py
+1
-1
rest_framework/tests/models.py
+4
-0
rest_framework/tests/serializer.py
+12
-1
No files found.
rest_framework/fields.py
View file @
46b31331
...
...
@@ -796,7 +796,7 @@ class ChoiceField(WritableField):
if
value
==
smart_unicode
(
k2
):
return
True
else
:
if
value
==
smart_unicode
(
k
):
if
value
==
smart_unicode
(
k
)
or
value
==
k
:
return
True
return
False
...
...
rest_framework/tests/models.py
View file @
46b31331
...
...
@@ -51,6 +51,10 @@ class RESTFrameworkModel(models.Model):
abstract
=
True
class
HasPositiveIntegerAsChoice
(
RESTFrameworkModel
):
some_choices
=
((
1
,
'A'
),(
2
,
'B'
),(
3
,
'C'
))
some_integer
=
models
.
PositiveIntegerField
(
choices
=
some_choices
)
class
Anchor
(
RESTFrameworkModel
):
text
=
models
.
CharField
(
max_length
=
100
,
default
=
'anchor'
)
...
...
rest_framework/tests/serializer.py
View file @
46b31331
...
...
@@ -2,7 +2,7 @@ import datetime
import
pickle
from
django.test
import
TestCase
from
rest_framework
import
serializers
from
rest_framework.tests.models
import
(
Album
,
ActionItem
,
Anchor
,
BasicModel
,
from
rest_framework.tests.models
import
(
HasPositiveIntegerAsChoice
,
Album
,
ActionItem
,
Anchor
,
BasicModel
,
BlankFieldModel
,
BlogPost
,
Book
,
CallableDefaultValueModel
,
DefaultValueModel
,
ManyToManyModel
,
Person
,
ReadOnlyManyToManyModel
,
Photo
)
...
...
@@ -69,6 +69,11 @@ class AlbumsSerializer(serializers.ModelSerializer):
model
=
Album
fields
=
[
'title'
]
# lists are also valid options
class
PositiveIntegerAsChoiceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
HasPositiveIntegerAsChoice
fields
=
[
'some_integer'
]
class
BasicTests
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -285,6 +290,12 @@ class ValidationTests(TestCase):
self
.
assertEquals
(
serializer
.
errors
,
{
'info'
:
[
u'Ensure this value has at most 12 characters (it has 13).'
]})
class
PositiveIntegerAsChoiceTests
(
TestCase
):
def
test_positive_integer_in_json_is_correctly_parsed
(
self
):
data
=
{
'some_integer'
:
1
}
serializer
=
PositiveIntegerAsChoiceSerializer
(
data
=
data
)
self
.
assertEquals
(
serializer
.
is_valid
(),
True
)
class
ModelValidationTests
(
TestCase
):
def
test_validate_unique
(
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