def post(self, request): access = UserAuth(request.user.id) if access['access'] == False: return Response({'message':access['details']}, status=status.HTTP_200_OK) data = self.request.data question_id = data['question'] has_an_answer = models.Answer.objects.filter(question = question_id).exists() if has_an_answer: return Response({'message': 'This question already has an answer'}, status=status.HTTP_200_OK) serializer = serializers.AnswerSerializers(data=data) if serializer.is_valid(): serializer.save( owner = self.request.user, is_active = True, ) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_200_OK)
def delete(self, request, pk): access = UserAuth(request.user.id) if access['access'] == False: return Response({'message':access['details']}, status=status.HTTP_200_OK) answer = models.Answer.objects.get(pk=pk) answer.is_active = False answer.save() return Response({'message': 'Removed'}, status=status.HTTP_200_OK)
def get(self, request): access = UserAuth(request.user.id) if access['access'] == False: return Response({'message':access['details']}, status=status.HTTP_200_OK) data = self.request.data user = data['user'] lesson_by_user = StudentCourse.objects.filter(user=user).values_list('lesson', flat=True) lessons_ids = models.Lesson.objects.filter(is_active = True).exclude(id__in = lesson_by_user).values_list('id', flat=True) lessons = models.Lesson.objects.filter(id__in = lessons_ids) serializer = serializers.LessonSerializers(lessons, many = True) return Response(serializer.data, status=status.HTTP_201_CREATED)
def post(self, request): access = UserAuth(request.user.id) if access['access'] == False: return Response({'message':access['details']}, status=status.HTTP_200_OK) data = self.request.data serializer = serializers.CourseSerializers(data=data) if serializer.is_valid(): serializer.save( owner = self.request.user, is_active = True, ) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_200_OK)
def put(self, request, pk): access = UserAuth(request.user.id) if access['access'] == False: return Response({'message':access['details']}, status=status.HTTP_200_OK) answer = models.Answer.objects.get(pk=pk) data = self.request.data serializer = serializers.AnswerSerializers(answer, data=data, partial=True) if serializer.is_valid(): serializer.save( owner = self.request.user, is_active = True, ) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_200_OK)