Opened 9 years ago
Closed 8 years ago
#26656 closed New feature (fixed)
Add timedelta support to DjangoJSONEncoder
Reported by: | Will Hardy | Owned by: | nobody |
---|---|---|---|
Component: | Core (Serialization) | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Chesco Igual | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently DjangoJSONEncoder
supports datetime
, date
, time
, Decimal
and UUID
objects.
But when the DurationField
was added recently, no support for timedelta
was added to the JSON encoder.
Change History (10)
comment:1 by , 9 years ago
Component: | Uncategorized → Core (Serialization) |
---|---|
Type: | Uncategorized → New feature |
comment:3 by , 9 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 9 years ago
Cc: | added |
---|---|
Triage Stage: | Accepted → Ready for checkin |
I gave a look at the code, and seems to solve the problem. Adds support for ISO durations. Includes new tests which seem to cover most of the cases (replicates previous duration tests, with the new ISO format).
Only thing is I am not able to tell if the format should be included anywhere in the official docs of the serializers or if it's not necessary.
comment:5 by , 9 years ago
Looks good! Reviewed as part of the Django sprint at PyCon.
tests.serializers.test_json:test_timedelta
passes with the patch. It fails without the patch.
The new TestParseISODurationRoundtrip
tests look good.
Does this need docs?
comment:6 by , 9 years ago
DjangoJSONEncoder
does not seem to be documented at all. I've added an entry to the release notes, and will open another ticket for the whole class to be documented.
comment:7 by , 9 years ago
See https://code.djangoproject.com/ticket/26704 for the DjangoJSONEncoder
documentation ticket.
comment:8 by , 9 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Now that #26704 is committed, we can update those docs for these changes.
comment:9 by , 9 years ago
Patch needs improvement: | unset |
---|
See discussion on a PR.