Working Ninja
2016-11-03T20:05:28
import json
import psycopg2
from psycopg2.extras import RealDictCursor

cursor = conn.cursor(cursor_factory=RealDictCursor)
objects = cursor.fetchall()

print json.dumps(objects, indent=2)

# Django
#JsonResponse({'objects': objects})

Source: https://www.peterbe.com/plog/from-postgres-to-json-strings

READ MORE

2016-11-11T16:55:21
import json

polls = Poll.objects.all()

# Convert our QuerySet into a list so polls can be serialized
print json.dumps(list(p), indent=2)
JsonResponse({'polls': list(polls)})

Source: http://stackoverflow.com/questions/7650448/django-serialize-queryset-values-into-json

READ MORE