Skip to content

Commit 86c5fa2

Browse files
committed
Force-evaluate querysets (see #2602)
1 parent 5688d8b commit 86c5fa2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

rest_framework/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from __future__ import unicode_literals
1414
from django.db import models
1515
from django.db.models.fields import FieldDoesNotExist, Field as DjangoModelField
16+
from django.db.models import query
1617
from django.utils.translation import ugettext_lazy as _
1718
from rest_framework.compat import postgres_fields, unicode_to_repr
1819
from rest_framework.utils import model_meta
@@ -562,7 +563,7 @@ def to_representation(self, data):
562563
"""
563564
# Dealing with nested relationships, data can be a Manager,
564565
# so, first get a queryset from the Manager if needed
565-
iterable = data.all() if isinstance(data, models.Manager) else data
566+
iterable = data.all() if isinstance(data, (models.Manager, query.QuerySet)) else data
566567
return [
567568
self.child.to_representation(item) for item in iterable
568569
]

0 commit comments

Comments
 (0)