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
df7c1144
Commit
df7c1144
authored
Jun 25, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3076 from jpadilla/issues/2704
Progressing #2704
parents
cd0c9b75
d6e30c75
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
rest_framework/serializers.py
+2
-2
tests/test_model_serializer.py
+25
-0
No files found.
rest_framework/serializers.py
View file @
df7c1144
...
@@ -13,7 +13,6 @@ response content is handled by parsers and renderers.
...
@@ -13,7 +13,6 @@ response content is handled by parsers and renderers.
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.db
import
models
from
django.db.models.fields
import
FieldDoesNotExist
,
Field
as
DjangoModelField
from
django.db.models.fields
import
FieldDoesNotExist
,
Field
as
DjangoModelField
from
django.db.models
import
query
from
django.utils.functional
import
cached_property
from
django.utils.functional
import
cached_property
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
rest_framework.compat
import
(
from
rest_framework.compat
import
(
...
@@ -579,7 +578,8 @@ class ListSerializer(BaseSerializer):
...
@@ -579,7 +578,8 @@ class ListSerializer(BaseSerializer):
"""
"""
# Dealing with nested relationships, data can be a Manager,
# Dealing with nested relationships, data can be a Manager,
# so, first get a queryset from the Manager if needed
# so, first get a queryset from the Manager if needed
iterable
=
data
.
all
()
if
isinstance
(
data
,
(
models
.
Manager
,
query
.
QuerySet
))
else
data
iterable
=
data
.
all
()
if
isinstance
(
data
,
models
.
Manager
)
else
data
return
[
return
[
self
.
child
.
to_representation
(
item
)
for
item
in
iterable
self
.
child
.
to_representation
(
item
)
for
item
in
iterable
]
]
...
...
tests/test_model_serializer.py
View file @
df7c1144
...
@@ -721,3 +721,28 @@ class TestSerializerMetaClass(TestCase):
...
@@ -721,3 +721,28 @@ class TestSerializerMetaClass(TestCase):
str
(
exception
),
str
(
exception
),
"Cannot set both 'fields' and 'exclude' options on serializer ExampleSerializer."
"Cannot set both 'fields' and 'exclude' options on serializer ExampleSerializer."
)
)
class
Issue2704TestCase
(
TestCase
):
def
test_queryset_all
(
self
):
class
TestSerializer
(
serializers
.
ModelSerializer
):
additional_attr
=
serializers
.
CharField
()
class
Meta
:
model
=
OneFieldModel
fields
=
(
'char_field'
,
'additional_attr'
)
OneFieldModel
.
objects
.
create
(
char_field
=
'abc'
)
qs
=
OneFieldModel
.
objects
.
all
()
for
o
in
qs
:
o
.
additional_attr
=
'123'
serializer
=
TestSerializer
(
instance
=
qs
,
many
=
True
)
expected
=
[{
'char_field'
:
'abc'
,
'additional_attr'
:
'123'
,
}]
assert
serializer
.
data
==
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