Django serializer gives object 'str' does not have attribute '_meta' error

I am trying to make a Django view that will give a JSON response with the earliest and latest objects. But, unfortunately, it does not work with this error.

'str' object has no attribute '_meta'

I have another serialization and it works.

Here is the code.

def get_calendar_limits(request):
    result =  serializers.serialize("json", Session.objects.aggregate(Max('date'), Min('date')), ensure_ascii=False)
    return HttpResponse(result, mimetype="application/javascript")

Thank you very much in advance.

+3
source share
3 answers

Take a look at the following:

objects= Session.objects.aggregate(Max('date'), Min('date'))
print [ type[o] for o in objects ]
result =  serializers.serialize("json", objects, ensure_ascii=False)

You might want to just run the above in interactive Python as an experiment.

What type of your objects? Is this type serialized?

0
source

I get the same error when trying to serialize an object that is not derived from Django Model

+1
source

Python "json". "" "" . .

+1

Source: https://habr.com/ru/post/1707183/


All Articles