Skip to content
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

Add a consistent display field to all REST API serializers #5891

Closed
jeremystretch opened this issue Feb 27, 2021 · 0 comments
Closed

Add a consistent display field to all REST API serializers #5891

jeremystretch opened this issue Feb 27, 2021 · 0 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@jeremystretch
Copy link
Member

Environment

  • Python version: 3.7.9
  • NetBox version: 2.10.5

Proposed Functionality

Add a new read-only field (e.g. _repr) to all REST API model serializers to convey the normalized representation of each object. This will always be a string suitable for display to a human user.

I'm open to suggestions regarding the specific name, though I am in favor of adopting the leading underscore to indicate a special-use field, in line with _depth on MPTT model serializers (which is used to effect object nesting in rendered selection lists).

Use Case

Establishing a consistent point of reference for API consumers greatly simplifies the logic needed to represent objects to human users. For example, the DynamicModelChoiceField form field accepts a display_field kwarg on initialization. This tells it which attribute of the model to display for each object in the generated selection list. For example, a Prefix will return its prefix attribute, whereas a DeviceType will return its model. Most models return their name.

By ensuring that every serializer includes this standard field, we obviate the need to specify these attributes.

Database Changes

None

External Dependencies

None

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application API change status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Feb 27, 2021
@jeremystretch jeremystretch added this to the v2.11 milestone Mar 2, 2021
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Mar 2, 2021
@jeremystretch jeremystretch self-assigned this Mar 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

1 participant