Force-evaluate querysets (see #2602)

This commit is contained in:
Danilo Bargen 2015-02-25 16:20:45 +01:00
parent 5688d8b736
commit 86c5fa2401

View File

@ -13,6 +13,7 @@ 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.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import postgres_fields, unicode_to_repr from rest_framework.compat import postgres_fields, unicode_to_repr
from rest_framework.utils import model_meta from rest_framework.utils import model_meta
@ -562,7 +563,7 @@ 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) else data iterable = data.all() if isinstance(data, (models.Manager, query.QuerySet)) else data
return [ return [
self.child.to_representation(item) for item in iterable self.child.to_representation(item) for item in iterable
] ]