I am trying to pass a queryset
as a JSON
object:
structure=Fund.objects.all().values('structure').annotate(total=Count('structure')).order_by('-total')
However, querysets
aren't Json Serializable
therefore, I modified my code:
from django.core import serializers
structure=serializers.serialize('json',Fund.objects.all().values('structure').annotate(total=Count('structure')).order_by('-total'))
But I get this error: AttributeError: 'dict' object has no attribute '_meta'
and this is my queryset: <QuerySet [{'total': 106, 'structure': 'Corp'}, {'total': 43, 'structure': 'Trust'}, {'total': 2, 'structure': 'OM'}, {'total': 0, 'structure': None}]>