Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
claytondaley opened this issue Sep 4, 2017 · 2 comments
Closed

Comments

@claytondaley
Copy link

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.

@carltongibson
Copy link
Collaborator

Parameterising the list serialiser class certainly seems valid. Happy to at least look at a PR on that.

@carltongibson
Copy link
Collaborator

I’m going to close this. Happy to see a simple solution as per #5393 but we’re not going to consider it an Open Issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants