views:

1152

answers:

3

Hello!

I am trying to make Django view that will give JSON responce with earliest and latest objects. But unfotunately it fails to work with this error.

'str' object has no attribute '_meta'

I have other 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")

Thanks a lot beforehand.

+1  A: 

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 are your objects? Is that type serializable?

S.Lott
You are right, there objects are not serializable. Thanks a lot.
freiksenet
+1  A: 

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

Michael
Yeah, I realized that I need to make my own serializer to serialize non-Django models.I solved this by just having a JSON template as I only needed this for one small bit.
freiksenet
+1  A: 

Python has "json" module. It can 'dumps' and 'loads' function. They can serialize and deserialize accordingly.

Andrey