[Django] #28208: DjangoJsonEncoder does not encode Queryset

7 views
Skip to first unread message

Django

unread,
May 15, 2017, 12:44:53 PM5/15/17
to django-...@googlegroups.com
#28208: DjangoJsonEncoder does not encode Queryset
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
AbrahamGo8 |
Type: New | Status: new
feature |
Component: Core | Version: 1.11
(Serialization) | Keywords: QuerySet
Severity: Normal | DjangoJSONEncoder
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django extends the standard JSON encoder from the standard library to
enhance its functionality, for example by providing methods to serialize
{{{datetimes}}} and {{{Decimal}}}.

Because {{{QuerySet}}} has a serialize method included in Django, why
don't use it in {{{DjangoJSONEncoder}}}?

--
Ticket URL: <https://code.djangoproject.com/ticket/28208>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 15, 2017, 12:58:36 PM5/15/17
to django-...@googlegroups.com
#28208: DjangoJsonEncoder does not encode Queryset
-------------------------------------+-------------------------------------
Reporter: AbrahamGo8 | Owner: nobody
Type: New feature | Status: new

Component: Core | Version: 1.11
(Serialization) |
Severity: Normal | Resolution:
Keywords: QuerySet | Triage Stage:
DjangoJSONEncoder | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Can you explain what you're trying to do? As far as I see, `QuerySet`
doesn't have a `serialize()` method.

--
Ticket URL: <https://code.djangoproject.com/ticket/28208#comment:1>

Django

unread,
May 16, 2017, 4:35:10 AM5/16/17
to django-...@googlegroups.com
#28208: DjangoJsonEncoder does not encode Queryset
-------------------------------------+-------------------------------------
Reporter: AbrahamGo8 | Owner: nobody
Type: New feature | Status: new
Component: Core | Version: 1.11
(Serialization) |
Severity: Normal | Resolution:
Keywords: QuerySet | Triage Stage:
DjangoJSONEncoder | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by AbrahamGo8):

Replying to [comment:1 Tim Graham]:


> Can you explain what you're trying to do? As far as I see, `QuerySet`
doesn't have a `serialize()` method.

Django provides us {{{django.core.serializers.serialize}}} function to
serialize a {{{QuerySet}}}.

I want to create a wrapper about {{{DjangoJSONEncoder}}} to include
{{{QuerySet}}} ({{{DjangoCustomJSONEncoder}}} for example) serialization
but it comes to mind if Django gives us a function to serialize a
{{{QuerySet}}} why Django does not include it into
{{{DjangoJSONEncoder}}}? So I think that there must be a major issue to
not include it.

Regards

--
Ticket URL: <https://code.djangoproject.com/ticket/28208#comment:2>

Django

unread,
May 17, 2017, 10:00:05 AM5/17/17
to django-...@googlegroups.com
#28208: DjangoJsonEncoder does not encode Queryset
-------------------------------------+-------------------------------------
Reporter: Abraham González | Owner: nobody
Ramírez |

Type: New feature | Status: new
Component: Core | Version: 1.11
(Serialization) |
Severity: Normal | Resolution:
Keywords: QuerySet | Triage Stage:
DjangoJSONEncoder | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Can you elaborate on the use case for creating a wrapper around
`DjangoJSONEncoder` to include `QuerySet`?

--
Ticket URL: <https://code.djangoproject.com/ticket/28208#comment:3>

Django

unread,
May 17, 2017, 12:41:16 PM5/17/17
to django-...@googlegroups.com
#28208: DjangoJsonEncoder does not encode Queryset
-------------------------------------+-------------------------------------
Reporter: Abraham González | Owner: nobody
Ramírez |
Type: New feature | Status: new
Component: Core | Version: 1.11
(Serialization) |
Severity: Normal | Resolution:
Keywords: QuerySet | Triage Stage:
DjangoJSONEncoder | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Abraham González Ramírez):

Replying to [comment:3 Tim Graham]:


> Can you elaborate on the use case for creating a wrapper around
`DjangoJSONEncoder` to include `QuerySet`?

We are using a Front-end framework that need to receive a JSON for
rendering a collection. So we need to include a {{{Queryset}} into a
wrapper of {{{DjangoJSONEncoder}}} to be able to serialize {{{QuerySet}}}

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/28208#comment:4>

Django

unread,
May 17, 2017, 1:50:47 PM5/17/17
to django-...@googlegroups.com
#28208: DjangoJsonEncoder does not encode Queryset
-------------------------------------+-------------------------------------
Reporter: Abraham González | Owner: nobody
Ramírez |
Type: New feature | Status: closed

Component: Core | Version: 1.11
(Serialization) |
Severity: Normal | Resolution: wontfix

Keywords: QuerySet | Triage Stage:
DjangoJSONEncoder | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => wontfix


Comment:

You might consider third-party packages such as [http://www.django-rest-
framework.org/ django REST framework] rather than building your own
serialization. I think queryset serialization is too nuanced (for example,
which fields should be serialized?) to add it to `DjangoJSONEncoder` which
serializes basic data types.

--
Ticket URL: <https://code.djangoproject.com/ticket/28208#comment:5>

Reply all
Reply to author
Forward
0 new messages