Open ITJamie opened 5 months ago
Add a read only field to the responses on the object-types API. allow filtering based on this "combined" field too
It's worth pointing out that merely adding a read-only field is trivial, but enabling it to be used for filtering is a bit more involved.
Also, Django refers to this as the "natural key" for a content type; we might want to adopt the same name for the serializer field & filter.
>>> from django.contrib.contenttypes.models import ContentType
>>> ContentType.objects.get_for_model(Site)
<ContentType: DCIM | site>
>>> ContentType.objects.get_for_model(Site).natural_key()
('dcim', 'site')
I guess adding it as an actual field to make it easy to filter would make sense. this endpoint is only really used in an informational way.
having it backfill the data into the model as part of migration wouldn't be hard.
as for the fieldname, natural_key would make a lot of sense, as long as it doesn't cause any kind of collision or confusion in the model
NetBox version
v4.0.3
Feature type
Data model extension
Proposed functionality
Add a read only field to the responses on the object-types API. allow filtering based on this "combined" field too EG:
Use case
other api endpoints sometimes return the combined
app_label.model
string. to reference other object types. eg on the interfaces API, an assigned interface returns"assigned_object_type": "dcim.interface"
. however to filter by that assigned_object_type you need to know the object-type id,being able to quickly use the combined string (eg
dcim.interface
) to quickly lookup the object-type id without doing any text manipulation would be greatDatabase changes
N/A
External dependencies
N/A