Hi,
I think you just want a option to use JsonResponse with QuerySet object.
let's think your question in this way: 'data serializations' question. 
queryset object can easy to dump by using django.core.serialzers, see 
this:https://docs.djangoproject.com/en/1.11/topics/serialization/
so you should queryset >> dict >> JsonResponse. easy, right?


On Wednesday, September 6, 2017 at 11:12:49 PM UTC+8, Ryan Fredericks wrote:
>
> Hello everyone,
>
> My name is Ryan and I've had the pleasure of working on various Django 
> backed projects for the last three or four years.  I've never contributed 
> to the project (yet) but I'd like to get started.  I'm posting today 
> because I'd like to discuss something that has irked me about JsonResponse 
> for a while.  I would love to submit a new PR for the feature I'm about to 
> describe, but I just wanted to run it by you all and hear some thoughts 
> first.
>
> Currently Django can grab data as QuerySets.  Those QuerySets are easily 
> serializable as json (or xml or whatever) via django.core.serializers. 
>  Since it is so easy to serialize a QuerySet as json, wouldn't it follow 
> that JsonResponse could handle a QuerySet?  Currently it does not, which 
> leaves the following 2 workarounds: 1) manually set the content-type header 
> in an HttpResponse, or 2) write some sort of crazy class that extends the 
> json dumps encoder and pass that through to JsonResponse.  I know its not a 
> huge deal, but how would you guys feel about either:
>
> A - detecting if the object passed to JsonResponse is a QuerySet and then 
> serializing it appropriately using the built in Django serializer instead 
> of json dumps
>
> B - Providing that json dumps encoder class to allow people to simply 
> include that when they want to pass in a QuerySet to a JsonResponse.
>
>
> I'd be happy to write something up and submit a PR if you guys think its 
> worth it/a good place to start contributing.
>
> Here's to hoping I can help contribute to many (much more) cool things in 
> the future,
> Ryan
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/b74662d6-35b7-49bb-9871-4c3b75f249c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to