Opened 8 years ago
Closed 8 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)
follow-up: 2 comment:1 by , 8 years ago
comment:2 by , 8 years ago
Replying to Tim Graham:
Can you explain what you're trying to do? As far as I see,
QuerySet
doesn't have aserialize()
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
follow-up: 4 comment:3 by , 8 years ago
Can you elaborate on the use case for creating a wrapper around DjangoJSONEncoder
to include QuerySet
?
comment:4 by , 8 years ago
Replying to Tim Graham:
Can you elaborate on the use case for creating a wrapper around
DjangoJSONEncoder
to includeQuerySet
?
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.
comment:5 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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.
Can you explain what you're trying to do? As far as I see,
QuerySet
doesn't have aserialize()
method.