Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert queryset to json django

from django.core import serializers
from django.http import HttpResponse

def some_view(request):
    qs = SomeModel.objects.all()
    qs_json = serializers.serialize('json', qs)
    return HttpResponse(qs_json, content_type='application/json')
Comment

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})
Comment

PREVIOUS NEXT
Code Example
Javascript :: send serialized form data jquery 
Javascript :: jquery hover and hover out 
Javascript :: create react native 
Javascript :: process.stdin.on("data", function (input) { _input += input; }); 
Javascript :: math.floor js 
Javascript :: javascript change color of text input 
Javascript :: javascript Using debugger 
Javascript :: read file in nodejs using fs 
Javascript :: nullish coalescing js 
Javascript :: jquery map 
Javascript :: Uncaught TypeError: Object prototype may only be an Object or null: undefined 
Javascript :: js replace multiple 
Javascript :: javascript regex cheat sheet 
Javascript :: angular bind style value 
Javascript :: upload form with doc type in ajax 
Javascript :: json limit nodejs 
Javascript :: react password hashing 
Javascript :: nodejs event 
Javascript :: js host without port 
Javascript :: selected angular select 
Javascript :: save canvas as image from website 
Javascript :: javascript collection to array 
Javascript :: how to get text from input js 
Javascript :: javascript calculate percentage to pixel 
Javascript :: moment js get date 1 month 
Javascript :: hwo to make ana array of prime numbers in javascript 
Javascript :: javascript get item in array by id 
Javascript :: how to add field to object in js 
Javascript :: js calculate distance between two coordinates 
Javascript :: divisible by 3 javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =