Created
December 28, 2014 21:37
-
-
Save leemac/bf0cef7ad214cfc950dd to your computer and use it in GitHub Desktop.
Example of returning a Django QuerySet as a JSON response (Django 1.7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the objects from the database | |
rawData = Launch.objects.all() | |
# Create array | |
json_res = [] | |
# Iterate over results and add to array | |
for record in rawData: | |
json_obj = dict(name = record.name) | |
json_res.append(json_obj) | |
# Return the results | |
return HttpResponse(json.dumps(json_res), content_type='application/json') |
Excellent approach! Thank a lot!
how to download it ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a tonne!