Skip to content

List serializer configuration would simplify drf-hal-json extension #5391

Closed
@claytondaley

Description

@claytondaley

drf-hal-json (linked to the active fork) is a 3rd party library that formats responses in compliance with the HAL spec. The HAL spec requires that all resources (including -list) be rendered as a dict with a link to its own URL (in _links.self.href).

The default behavior of DRF for an unpaged -list resource is to render it as a list of dict. Obviously, a list cannot have a _links key so the PR at Antory\drf-hal-json#20:

  • replaces the default ListSerializer with a HalListSerializer
  • constructs a link for the -list of the resource

Any 3rd party formatter that is incompatible with a top-level ListSerializer would require a similar change. Unfortunately. the default ListSerializer is hard coded in many_init. To (1) continue to support a user-defined Meta value, (2) change the default, and (3) avoid duplicating core code, the PR conditionally injects the new default into Meta. It would be simpler/cleaner if the default was configurable on the class and could be overridden by the HalModelSerializer.

The infrastructure for constructing -detail URLs is also spread across several files. This plugin needed the same for -list. Because there's no call supporting view_name, the PR adds a meta option to override the default. I'm not sure if the same setting would be any help in the core, but wanted to at least draw attention to it as it might eliminate the need for a view_name in other cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions