Opened 3 years ago

Closed 3 years ago

#28208 closed New feature (wontfix)

DjangoJsonEncoder does not encode Queryset

Reported by: Abraham González Ramírez Owned by: nobody
Component: Core (Serialization) Version: 1.11
Severity: Normal Keywords: QuerySet DjangoJSONEncoder
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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?

Change History (5)

comment:1 Changed 3 years ago by Tim Graham

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

comment:2 in reply to:  1 Changed 3 years ago by Abraham González Ramírez

Replying to 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

comment:3 Changed 3 years ago by Tim Graham

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

comment:4 in reply to:  3 Changed 3 years ago by Abraham González Ramírez

Replying to 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 DjangoJSONEncoder wrapper to be able to serialize it

Thanks.

Last edited 3 years ago by Abraham González Ramírez (previous) (diff)

comment:5 Changed 3 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

You might consider third-party packages such as 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.

Note: See TracTickets for help on using tickets.
Back to Top