|
@@ -15,30 +15,30 @@ class FavoritecontactsMVS(viewsets.ModelViewSet):
|
|
|
]
|
|
|
|
|
|
def list(self, request, *args, **kwargs):
|
|
|
- client_id = self.request.query_params.get('client_id')
|
|
|
+ client = self.request.query_params.get('client')
|
|
|
queryset = Favoritecontacts.objects.all()
|
|
|
- if client_id is not None:
|
|
|
+ if client is not None:
|
|
|
queryset = queryset \
|
|
|
- .annotate(client_id_int=Cast('client_id', output_field=CharField())) \
|
|
|
- .filter(client_id_int=client_id)
|
|
|
+ .annotate(client_int=Cast('client', output_field=CharField())) \
|
|
|
+ .filter(client_int=client)
|
|
|
serializer = self.get_serializer(queryset, many=True)
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
|
- client_id = self.request.query_params.get('client_id')
|
|
|
+ client = self.request.query_params.get('client')
|
|
|
queryset = Favoritecontacts.objects.all()
|
|
|
- if not client_id:
|
|
|
+ if not client:
|
|
|
return Response(
|
|
|
- {'error': 'client_id parameter is required'},
|
|
|
+ {'error': 'client parameter is required'},
|
|
|
status=status.HTTP_400_BAD_REQUEST
|
|
|
)
|
|
|
|
|
|
queryset = queryset \
|
|
|
- .annotate(client_id_int=Cast('client_id', output_field=CharField())) \
|
|
|
- .filter(client_id_int=client_id)
|
|
|
+ .annotate(client_int=Cast('client', output_field=CharField())) \
|
|
|
+ .filter(client_int=client)
|
|
|
queryset.delete()
|
|
|
|
|
|
return Response(
|
|
|
- {'message': f'Objects with client_id {client_id} were deleted'},
|
|
|
+ {'message': f'Objects with client {client} were deleted'},
|
|
|
status=status.HTTP_204_NO_CONTENT
|
|
|
)
|