Add a consistent display field to all REST API serializers #5891
Labels
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
Milestone
Environment
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 itsprefix
attribute, whereas a DeviceType will return itsmodel
. Most models return theirname
.By ensuring that every serializer includes this standard field, we obviate the need to specify these attributes.
Database Changes
None
External Dependencies
None
The text was updated successfully, but these errors were encountered: