Skip to content

Commit 436322d

Browse files
authored
Expose table_model_name and object_type_name in CustomObjectType API response (#309)
1 parent 4cf36b9 commit 436322d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

netbox_custom_objects/api/serializers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rest_framework.reverse import reverse
1111
from rest_framework.utils import model_meta
1212

13-
from netbox_custom_objects import field_types
13+
from netbox_custom_objects import constants, field_types
1414
from netbox_custom_objects.models import (CustomObject, CustomObjectType,
1515
CustomObjectTypeField)
1616

@@ -117,6 +117,8 @@ class CustomObjectTypeSerializer(NetBoxModelSerializer):
117117
read_only=True,
118118
many=True,
119119
)
120+
table_model_name = serializers.SerializerMethodField()
121+
object_type_name = serializers.SerializerMethodField()
120122

121123
class Meta:
122124
model = CustomObjectType
@@ -132,9 +134,17 @@ class Meta:
132134
"created",
133135
"last_updated",
134136
"fields",
137+
"table_model_name",
138+
"object_type_name",
135139
]
136140
brief_fields = ("id", "url", "name", "slug", "description")
137141

142+
def get_table_model_name(self, obj):
143+
return obj.get_table_model_name(obj.id)
144+
145+
def get_object_type_name(self, obj):
146+
return f"{constants.APP_LABEL}.{obj.get_table_model_name(obj.id).lower()}"
147+
138148
def create(self, validated_data):
139149
return super().create(validated_data)
140150

0 commit comments

Comments
 (0)