Exemple #1
0
 def post(self, request, *args, **kwargs):
     salon = models.Salon.objects.get(pk=self.kwargs[self.lookup_field])
     name = request.data.get('name')
     service = models.Service(salon=salon, name=name)
     if service:
         service.save()
         data = {'salon': serializers.SalonSerializer(salon)}
         serializer = serializers.ServiceSerializer(service)
         headers = self.get_success_headers(serializer.data)
         return Response(serializer.data,
                         status=status.HTTP_201_CREATED,
                         headers=headers)
     return Response({'error': 'Invalid data'},
                     status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
 def create(self, validated_data):
     service = models.Service(**validated_data)
     service.save
     return service