Back to Blog
You can specifiy the fields you wish to use in values() in the serialize() method as follows: from re import serializersįunds = ().annotate(total=Count('structure')). But values() doesn't return queryset, rather a ValuesQuerySet object. Structure=rialize('json',().values('structure').annotate(total=Count('structure')).order_by('-total'))īut I get this error: AttributeError: 'dict' object has no attribute '_meta' and this is my queryset: ĭjango core serializers can only serialize a queryset. In an HttpRequest object, the GET and POST attributes are instances of, a dictionary-like class customized to deal with multiple values. However, querysets aren't Json Serializable therefore, I modified my code: from re import serializers Structure=().values('structure').annotate(total=Count('structure')).order_by('-total') I am trying to pass a queryset as a JSON object:
0 Comments
Read More
Leave a Reply. |