Serialization to JSON two querysets in Django

django, json, python, serialization

Solution

from itertools import chain
combined = list(chain(collectionA, collectionB))

json = serializers.serialize('json', combined)

Problem

I've some problem with JSON serialization two objects of type queryset in my Django project. For example I have: ``` collectionA = A.objects.all() collectionB = B.objects.all() ``` When I try ot serialize only one collection: ``` json = serializers.serialize('json', collectionA) ``` then everything works properly, but how can I serialize these two collections to one json object?

Original source

Related problems