def create(self, request, *args, **kwargs): serializer = self.serializer_class(data=request.data) serializer.is_valid(raise_exception=True) validate_funds(request.user, float(request.data['price'])) self.perform_create(serializer) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def join(self, request, pk=None): instance = self.queryset.get(pk=pk) validate_funds(request.user, instance.price) instance.users.add(request.user) instance.save() serializer = self.serializer_class(initial=instance) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)