mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 19:14:01 +03:00
Add test and fix for #2704
This commit is contained in:
parent
cd0c9b7555
commit
d6e30c75ff
|
@ -13,7 +13,6 @@ response content is handled by parsers and renderers.
|
|||
from __future__ import unicode_literals
|
||||
from django.db import models
|
||||
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.translation import ugettext_lazy as _
|
||||
from rest_framework.compat import (
|
||||
|
@ -579,7 +578,8 @@ class ListSerializer(BaseSerializer):
|
|||
"""
|
||||
# Dealing with nested relationships, data can be a Manager,
|
||||
# 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 [
|
||||
self.child.to_representation(item) for item in iterable
|
||||
]
|
||||
|
|
|
@ -721,3 +721,28 @@ class TestSerializerMetaClass(TestCase):
|
|||
str(exception),
|
||||
"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
|
||||
|
|
Loading…
Reference in New Issue
Block a user