Fakultas Ilmu Komputer UI

Commit 2482e004 authored by Joshua Casey's avatar Joshua Casey
Browse files

[#46] Modified student serializer to include number of companies accepting him

parent fcd5a4a7
......@@ -2,7 +2,7 @@ from django.contrib.auth.models import User
from rest_framework import serializers
from core.models.accounts import Supervisor, Company, Student
from core.models.vacancies import Application
class BasicUserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
......@@ -13,11 +13,17 @@ class BasicUserSerializer(serializers.HyperlinkedModelSerializer):
class StudentSerializer(serializers.ModelSerializer):
user = BasicUserSerializer()
name = serializers.ReadOnlyField()
accepted_no = serializers.SerializerMethodField()
class Meta:
model = Student
fields = ['id', 'name', 'user', 'npm', 'resume', 'phone_number', 'birth_place', 'birth_date', 'major', 'batch', \
'show_transcript', 'photo']
'show_transcript', 'photo', 'accepted_no']
def get_accepted_no(self, obj):
apps = Application.objects.filter(student=obj, status=4)
companies = apps.values('vacancy__company').distinct()
return companies.count()
class StudentUpdateSerializer(serializers.ModelSerializer):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment