Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert queryset to json django

from django.http import JsonResponse

def some_view(request):
    data = list(SomeModel.objects.values())  # wrap in list(), because QuerySet is not JSON serializable
    return JsonResponse(data, safe=False)  # or JsonResponse({'data': data})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #queryset #json #django
ADD COMMENT
Topic
Name
7+4 =