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
aa72f8d6
Commit
aa72f8d6
authored
Dec 17, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug with M2M in browseable API
parent
70714c23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
8 deletions
+38
-8
rest_framework/renderers.py
+1
-1
rest_framework/serializers.py
+3
-7
rest_framework/tests/generics.py
+34
-0
No files found.
rest_framework/renderers.py
View file @
aa72f8d6
...
...
@@ -20,7 +20,7 @@ from rest_framework.utils import dict2xml
from
rest_framework.utils
import
encoders
from
rest_framework.utils.breadcrumbs
import
get_breadcrumbs
from
rest_framework
import
VERSION
,
status
from
rest_framework
import
serializers
,
parsers
from
rest_framework
import
parsers
class
BaseRenderer
(
object
):
...
...
rest_framework/serializers.py
View file @
aa72f8d6
...
...
@@ -160,6 +160,9 @@ class BaseSerializer(Field):
for
key
in
self
.
opts
.
exclude
:
ret
.
pop
(
key
,
None
)
for
key
,
field
in
ret
.
items
():
field
.
initialize
(
parent
=
self
,
field_name
=
key
)
return
ret
#####
...
...
@@ -174,13 +177,6 @@ class BaseSerializer(Field):
if
parent
.
opts
.
depth
:
self
.
opts
.
depth
=
parent
.
opts
.
depth
-
1
# We need to call initialize here to ensure any nested
# serializers that will have already called initialize on their
# descendants get updated with *their* parent.
# We could be a bit more smart about this, but it'll do for now.
for
key
,
field
in
self
.
fields
.
items
():
field
.
initialize
(
parent
=
self
,
field_name
=
key
)
#####
# Methods to convert or revert from objects <--> primitive representations.
...
...
rest_framework/tests/generics.py
View file @
aa72f8d6
from
django.db
import
models
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
django.utils
import
simplejson
as
json
...
...
@@ -301,3 +302,36 @@ class TestCreateModelWithAutoNowAddField(TestCase):
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
created
=
self
.
objects
.
get
(
id
=
1
)
self
.
assertEquals
(
created
.
content
,
'foobar'
)
# Test for particularly ugly reression with m2m in browseable API
class
ClassB
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
255
)
class
ClassA
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
255
)
childs
=
models
.
ManyToManyField
(
ClassB
,
blank
=
True
,
null
=
True
)
class
ClassASerializer
(
serializers
.
ModelSerializer
):
childs
=
serializers
.
ManyPrimaryKeyRelatedField
(
source
=
'childs'
)
class
Meta
:
model
=
ClassA
class
ExampleView
(
generics
.
ListCreateAPIView
):
serializer_class
=
ClassASerializer
model
=
ClassA
class
TestM2MBrowseableAPI
(
TestCase
):
def
test_m2m_in_browseable_api
(
self
):
"""
Test for particularly ugly reression with m2m in browseable API
"""
request
=
factory
.
get
(
'/'
,
HTTP_ACCEPT
=
'text/html'
)
view
=
ExampleView
()
.
as_view
()
response
=
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
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