Fakultas Ilmu Komputer UI

accounts.py 1.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
from django.contrib.auth.models import User
from rest_framework import serializers

from core.models.accounts import Supervisor, Company, Student


class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')


class StudentSerializer(serializers.ModelSerializer):
Zamil Majdy's avatar
Zamil Majdy committed
14
15
16
    user = UserSerializer()
    name = serializers.ReadOnlyField()

17
18
19
20
21
22
    class Meta:
        model = Student
        fields = '__all__'


class CompanySerializer(serializers.ModelSerializer):
Zamil Majdy's avatar
Zamil Majdy committed
23
24
25
    user = UserSerializer()
    name = serializers.ReadOnlyField()

26
27
28
29
30
31
    class Meta:
        model = Company
        fields = '__all__'


class SupervisorSerializer(serializers.ModelSerializer):
Zamil Majdy's avatar
Zamil Majdy committed
32
33
34
    user = UserSerializer()
    name = serializers.ReadOnlyField()

35
36
    class Meta:
        model = Supervisor
Zamil Majdy's avatar
Zamil Majdy committed
37
        fields = '__all__'
38
39
40
41
42
43
44
45
46
47
48


class LoginSerializer(serializers.HyperlinkedModelSerializer):
    company = CompanySerializer()
    supervisor = SupervisorSerializer()
    student = StudentSerializer()

    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff', 'company', 'supervisor', 'student')