@ -1,5 +1,7 @@
|
||||
from rest_framework import serializers
|
||||
from django.urls import reverse
|
||||
|
||||
from itam.models.device import Device
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
|
||||
@ -11,11 +13,11 @@ class DeviceSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
|
||||
config = serializers.SerializerMethodField('get_device_config')
|
||||
|
||||
|
||||
def get_device_config(self, device):
|
||||
|
||||
return device.get_configuration(device.id)
|
||||
|
||||
request = self.context.get('request')
|
||||
return request.build_absolute_uri(reverse('_api_device_config', args=[device.slug]))
|
||||
|
||||
|
||||
class Meta:
|
||||
@ -23,6 +25,7 @@ class DeviceSerializer(serializers.ModelSerializer):
|
||||
fields = '__all__'
|
||||
|
||||
read_only_fields = [
|
||||
'is_global',
|
||||
'organization',
|
||||
]
|
||||
|
||||
|
@ -13,7 +13,7 @@ urlpatterns = [
|
||||
path("organization/team/", access.TeamList.as_view(), name='_api_teams'),
|
||||
|
||||
|
||||
path("config/<str:device_name>/", itam_config.View.as_view(), name="_api_device_config"),
|
||||
path("config/<slug:slug>/", itam_config.View.as_view(), name="_api_device_config"),
|
||||
|
||||
path("device/", itam_device.List.as_view(), name="_api_devices"),
|
||||
path("device/<int:pk>/", itam_device.Detail.as_view(), name="_api_device_view"),
|
||||
|
@ -8,9 +8,9 @@ from rest_framework.response import Response
|
||||
|
||||
class View(views.APIView):
|
||||
|
||||
def get(self, request, device_name):
|
||||
def get(self, request, slug):
|
||||
|
||||
device = Device.objects.get(slug=device_name)
|
||||
device = Device.objects.get(slug=slug)
|
||||
|
||||
return Response(device.get_configuration(device.id))
|
||||
|
||||
|
Reference in New Issue
Block a user