2018-10-12 Django serializers.serialize("json", data) AttributeError: 'dict' object has no attrib...

https://stackoverflow.com/questions/46062242/queryset-serialize-attributeerror-dict-object-has-no-attribute-meta?noredirect=1&lq=1

    data = SampleProductStatus.objects.filter(sample__customer_id=request.user.username).values('status')\
        .annotate(count=Count('status')).values('status', 'count')
    # 下面方法会出现 AttributeError: 'dict' object has no attribute '_meta'
    # qs_json = serializers.serialize('json', data)
    # 下面方法会出现 TypeError: Object of type 'QuerySet' is not JSON serializable
    # resp = json.dumps(data)
    resp = json.dumps(list(data), cls=DjangoJSONEncoder)

你可能感兴趣的:(2018-10-12 Django serializers.serialize("json", data) AttributeError: 'dict' object has no attrib...)