@ -69,7 +69,13 @@ class ClusterTypeModelSerializer(
|
||||
'model_pk': item.pk
|
||||
}
|
||||
),
|
||||
'notes': reverse("v2:_api_v2_cluster_type_notes-list", request=self._context['view'].request, kwargs={'cluster_type_id': item.pk}),
|
||||
'notes': reverse(
|
||||
"v2:_api_v2_cluster_type_note-list",
|
||||
request=self._context['view'].request,
|
||||
kwargs={
|
||||
'model_id': item.pk
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
66
app/itim/viewsets/cluster_type_notes.py
Normal file
66
app/itim/viewsets/cluster_type_notes.py
Normal file
@ -0,0 +1,66 @@
|
||||
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse
|
||||
|
||||
from core.viewsets.model_notes import ModelNoteViewSet
|
||||
|
||||
from itim.serializers.cluster_type_notes import (
|
||||
ClusterTypeNotes,
|
||||
ClusterTypeNoteModelSerializer,
|
||||
ClusterTypeNoteViewSerializer
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
create=extend_schema(
|
||||
summary = 'Add a note to a Cluster Type',
|
||||
description = '',
|
||||
responses = {
|
||||
201: OpenApiResponse(description='created', response=ClusterTypeNoteViewSerializer),
|
||||
400: OpenApiResponse(description='Validation failed.'),
|
||||
403: OpenApiResponse(description='User is missing create permissions'),
|
||||
}
|
||||
),
|
||||
destroy = extend_schema(
|
||||
summary = 'Delete a Cluster Type note',
|
||||
description = ''
|
||||
),
|
||||
list = extend_schema(
|
||||
summary = 'Fetch all Cluster Type notes',
|
||||
description='',
|
||||
),
|
||||
retrieve = extend_schema(
|
||||
summary = 'Fetch a single Cluster Type note',
|
||||
description='',
|
||||
),
|
||||
update = extend_schema(exclude = True),
|
||||
partial_update = extend_schema(
|
||||
summary = 'Update a Cluster Type note',
|
||||
description = ''
|
||||
),
|
||||
)
|
||||
class ViewSet(ModelNoteViewSet):
|
||||
|
||||
model = ClusterTypeNotes
|
||||
|
||||
|
||||
def get_serializer_class(self):
|
||||
|
||||
if self.serializer_class is not None:
|
||||
|
||||
return self.serializer_class
|
||||
|
||||
|
||||
if (
|
||||
self.action == 'list'
|
||||
or self.action == 'retrieve'
|
||||
):
|
||||
|
||||
self.serializer_class = ClusterTypeNoteViewSerializer
|
||||
|
||||
|
||||
else:
|
||||
|
||||
self.serializer_class = ClusterTypeNoteModelSerializer
|
||||
|
||||
return self.serializer_class
|
Reference in New Issue
Block a user