Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion netbox_custom_objects/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rest_framework.reverse import reverse
from rest_framework.utils import model_meta

from netbox_custom_objects import field_types
from netbox_custom_objects import constants, field_types
from netbox_custom_objects.models import (CustomObject, CustomObjectType,
CustomObjectTypeField)

Expand Down Expand Up @@ -117,6 +117,8 @@ class CustomObjectTypeSerializer(NetBoxModelSerializer):
read_only=True,
many=True,
)
table_model_name = serializers.SerializerMethodField()
object_type_name = serializers.SerializerMethodField()

class Meta:
model = CustomObjectType
Expand All @@ -132,9 +134,17 @@ class Meta:
"created",
"last_updated",
"fields",
"table_model_name",
"object_type_name",
]
brief_fields = ("id", "url", "name", "slug", "description")

def get_table_model_name(self, obj):
return obj.get_table_model_name(obj.id)

def get_object_type_name(self, obj):
return f"{constants.APP_LABEL}.{obj.get_table_model_name(obj.id).lower()}"

def create(self, validated_data):
return super().create(validated_data)

Expand Down