Django : json serialize a queryset which uses defer() or only()
- by PlanetUnknown
Now I've been using json serializer and it works great.
I had to modify my queries where I started using the only() & defer() filters, like so -
retObj = OBJModel.objects.defer("create_dt").filter(loged_in_dt__gte=dtStart)
After I've done the above, suddenly the json serializer is returning empty fields -
{"pk": 19047, "model": "OBJModel_deferred_create_dt", "fields": {}}
If I remove the defer(), the serializer gives all the data correctly.
import json
from django.utils import simplejson
from django.core import serializers
json_serializer = serializers.get_serializer("json")()
retObj = OBJModel.objects.defer("create_dt").filter(loged_in_dt__gte=dtStart)
json_serializer.serialize(retObj, ensure_ascii=False)
I've scratched my head on this for a while now. Any insight would be great.
NOTE : I am using django 1.1