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
fd97d9bf
Commit
fd97d9bf
authored
Nov 13, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use select inputs for relationships. Closes #2058.
parent
ea98de9b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
7 deletions
+10
-7
rest_framework/relations.py
+6
-6
rest_framework/renderers.py
+4
-1
No files found.
rest_framework/relations.py
View file @
fd97d9bf
...
...
@@ -34,13 +34,13 @@ class RelatedField(Field):
def
__new__
(
cls
,
*
args
,
**
kwargs
):
# We override this method in order to automagically create
# `ManyRelat
ion
` classes instead when `many=True` is set.
# `ManyRelat
edField
` classes instead when `many=True` is set.
if
kwargs
.
pop
(
'many'
,
False
):
list_kwargs
=
{
'child_relation'
:
cls
(
*
args
,
**
kwargs
)}
for
key
in
kwargs
.
keys
():
if
key
in
MANY_RELATION_KWARGS
:
list_kwargs
[
key
]
=
kwargs
[
key
]
return
ManyRelat
ion
(
**
list_kwargs
)
return
ManyRelat
edField
(
**
list_kwargs
)
return
super
(
RelatedField
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
def
run_validation
(
self
,
data
=
empty
):
...
...
@@ -286,12 +286,12 @@ class SlugRelatedField(RelatedField):
return
getattr
(
obj
,
self
.
slug_field
)
class
ManyRelat
ion
(
Field
):
class
ManyRelat
edField
(
Field
):
"""
Relationships with `many=True` transparently get coerced into instead being
a ManyRelat
ion
with a child relationship.
a ManyRelat
edField
with a child relationship.
The `ManyRelat
ion
` class is responsible for handling iterating through
The `ManyRelat
edField
` class is responsible for handling iterating through
the values and passing each one to the child relationship.
You shouldn't need to be using this class directly yourself.
...
...
@@ -302,7 +302,7 @@ class ManyRelation(Field):
def
__init__
(
self
,
child_relation
=
None
,
*
args
,
**
kwargs
):
self
.
child_relation
=
child_relation
assert
child_relation
is
not
None
,
'`child_relation` is a required argument.'
super
(
ManyRelat
ion
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
ManyRelat
edField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
child_relation
.
bind
(
field_name
=
''
,
parent
=
self
)
def
get_value
(
self
,
dictionary
):
...
...
rest_framework/renderers.py
View file @
fd97d9bf
...
...
@@ -383,7 +383,10 @@ class HTMLFormRenderer(BaseRenderer):
serializers
.
MultipleChoiceField
:
{
'base_template'
:
'select_multiple.html'
,
# Also valid: 'checkbox_multiple.html'
},
serializers
.
ManyRelation
:
{
serializers
.
RelatedField
:
{
'base_template'
:
'select.html'
,
# Also valid: 'radio.html'
},
serializers
.
ManyRelatedField
:
{
'base_template'
:
'select_multiple.html'
,
# Also valid: 'checkbox_multiple.html'
},
serializers
.
Serializer
:
{
...
...
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