Commit df7c1144 by Tom Christie

Merge pull request #3076 from jpadilla/issues/2704

Progressing #2704
parents cd0c9b75 d6e30c75
...@@ -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
] ]
......
...@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment