Skip to content

Instantly share code, notes, and snippets.

@subh007
Forked from anonymous/gist:5952347
Last active August 29, 2015 14:09
Show Gist options
  • Save subh007/83902b028bf1a4d0a68a to your computer and use it in GitHub Desktop.
Save subh007/83902b028bf1a4d0a68a to your computer and use it in GitHub Desktop.
from django.utils import simplejson
from django.core import serializers
from models import Apple, Orange
def AjaxQuery(request):
apple_json = serializers.serialize('json', Apples.objects.all() )
apple_list = simplejson.loads( apple_json )
orange_json = serializers.serialize('json', Orange.objects.all() )
orange_list = simplejson.loads( orange_json )
json_data = simplejson.dumps( {'oranges':orange_list, 'apples':apple_list} )
return HttpResponse( json_data, mimetype='application/json' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment