1 2 3 4 5 6 7 8 9 10 11 12 | from django.core.serializers import serialize from django.db.models.query import QuerySet from django.http import HttpResponse from django.utils import simplejson class JsonResponse(HttpResponse): def __init__(self, object): if isinstance(object, QuerySet): content = serialize('json', object) else: content = simplejson.dumps(object) super(JsonResponse, self).__init__(content, mimetype='application/json') |
Comments