def post(self, request, project_id, format=None): serializer = IntervalSerializer(data=request.data) project = Project.objects.get(pk=project_id, user=request.user.id) if serializer.is_valid(): serializer.save(project=project) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, project_id, pk, format=None): interval = self.get_object(project_id, pk, request) serializer = IntervalSerializer(interval, data=request.data) if serializer.is_valid(): serializer.save() project_object = self.get_project(project_id, request) project = ProjectSerializer(project_object) return Response(project.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def AllIntervals(request, format=None): intervals = Interval.objects.filter(project__user=request.user.id) serializer = IntervalSerializer(intervals, many=True) return Response(serializer.data)
def get(self, request, project_id, pk, format=None): interval = self.get_object(project_id, pk, request) serializer = IntervalSerializer(interval) return Response(serializer.data)
def get(self, request, project_id, format=None): project = Project.objects.get(pk=project_id, user=request.user.id) intervals = project.intervals.all().order_by('-created_at') serializer = IntervalSerializer(intervals, many=True) return Response(serializer.data)