-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
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