Hello/thoughts on JsonResponse

125 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Ryan Fredericks

belum dibaca,
6 Sep 2017, 11.12.4906/09/17
kepadaDjango developers (Contributions to Django itself)
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

Jani Tiainen

belum dibaca,
7 Sep 2017, 01.42.2207/09/17
kepadadjango-d...@googlegroups.com

Hi,

Since your proposal can live easily out of Django core as a 3rd party functionality you should start by implementing it, rather than waiting for official green light.

And that as said, since it can live very easily outside of Django you should really convince that this is something worth of including in the core. Or is there something that can't be done without changing Django internals?
--
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 django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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/01c11ccd-6017-44e4-b31a-0f5bb08b386d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

callsa...@gmail.com

belum dibaca,
7 Sep 2017, 07.16.1607/09/17
kepadaDjango developers (Contributions to Django itself)
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?
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru