Opened 7 years ago

Closed 7 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 by Tim Graham, 7 years ago

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

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

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 by Tim Graham, 7 years ago

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

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

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 wrapper of DjangoJSONEncoder to be able to serialize QuerySet

Thanks.

Version 1, edited 7 years ago by Abraham González Ramírez (previous) (next) (diff)

comment:5 by Tim Graham, 7 years ago

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