SHARE
TWEET

Untitled

a guest Mar 24th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from rest_framework import viewsets
  2. from quickstart.serializers import *
  3. from .models import Candidate, Recruiter, Task, Grade
  4.  
  5. # API endpoint that allows groups to be viewed or edited.
  6.  
  7. class CandidateViewSet(viewsets.ModelViewSet):
  8.    
  9.     queryset = Candidate.objects.all()
  10.     serializer_class = CandidateSerializer
  11.  
  12. class RecruiterViewSet(viewsets.ModelViewSet):
  13.    
  14.     queryset = Recruiter.objects.all()
  15.     serializer_class = RecruiterSerializer
  16.  
  17. class TaskViewSet(viewsets.ModelViewSet):
  18.  
  19.     queryset = Task.objects.all()
  20.     serializer_class = TaskSerializer
  21.  
  22. class GradeViewSet(viewsets.ModelViewSet):
  23.    
  24.     queryset = Grade.objects.all()
  25.     serializer_class = GradeSerializer
  26.  
  27. class AllAboutViewSet(viewsets.ModelViewSet):
  28.  
  29.     candidates = Candidate.objects.all()
  30.     grades = Grade.objects.all()
  31.  
  32.     for candidate in candidates:
  33.         candidate.grades = Grade.objects.filter(candidate_id = candidate.id).values_list('value', flat=True)
  34.         print(str(len(candidate.grades)))
  35.         print(str(candidate.grades))
  36.  
  37.         if len(candidate.grades) != 0:
  38.             gradeSum = sum(candidate.grades)
  39.             gradeLength = len(candidate.grades)
  40.             candidate.avg = round(gradeSum/gradeLength, 2)
  41.         else:    
  42.             candidate.avg = 0
  43.         print(str(candidate.avg))
  44.         print("oceny " + candidate.last_name + " " + str(candidate.grades))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top