Exemplo n.º 1
0
    def update_topics(self, request, pk=None):
        exam = self.get_object()

        new_topics = request.data.get('new_topics')
        exam.topics = new_topics
        exam.save()

        return Response(ExamSerializer(exam).data)
Exemplo n.º 2
0
    def update_title(self, request, pk=None):
        exam = self.get_object()

        new_title = request.data.get('new_title')
        exam.title = new_title
        exam.save()

        return Response(ExamSerializer(exam).data)
Exemplo n.º 3
0
    def update_course(self, request, pk=None):
        exam = self.get_object()

        new_course = request.data.get('new_course')
        courseNew = Course.objects.get(id=new_course)
        exam.course = courseNew
        exam.save()

        return Response(ExamSerializer(exam).data)
Exemplo n.º 4
0
    def update_date(self, request, pk=None):
        exam = self.get_object()

        new_date = request.data.get('new_date')
        new_date = datetime.datetime.strptime(new_date, '%Y-%m-%d').date()
        exam.date = new_date
        exam.save()

        return Response(ExamSerializer(exam).data)
Exemplo n.º 5
0
 def exams(self, request, pk=None):
     course = self.get_object()
     exams_course=[]
     for exam in Exam.objects.filter(course=course):
          exams_course.append(ExamSerializer(exam).data)
     return Response(exams_course)
Exemplo n.º 6
0
 def exams(self, request, pk=None):
     student = self.get_object()
     exams_user = []
     for exam in Exam.objects.filter(student=student):
         exams_user.append(ExamSerializer(exam).data)
     return Response(exams_user)
Exemplo n.º 7
0
 def get(self, request):
     # query_set = exam.objects.all()
     query_set = exam.objects.filter(user=request.user, id=request.data.id)
     serializer = ExamSerializer(query_set, many=True)
     return Response(serializer.data)
Exemplo n.º 8
0
 def post(self, request):
     serializer = ExamSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)