Skip to content

core.renderers ​

Overview ​

JSON rendering for VUEDA responses.

DRF's own encoder renders a timedelta as str(obj.total_seconds()) -- a JSON string, not a JSON number. That is a reasonable default for a serializer field, whose declared type is a string either way, but it is wrong for a value that never passes through a serializer field at all. A Sum over a DurationField is exactly that: get_column_info puts the aggregate straight into the response, so a duration total would reach a client as "3600.0" where every other total is a number, and where the paginated response schema promises a number.

So the encoder below renders durations as seconds, and the two renderers exist only to use it. DRF reads the encoder off the renderer class rather than from a setting, so a project cannot swap it in through REST_FRAMEWORK alone.

Classes ​

Source ​

server/vueda/core/renderers.py