universityScholarship.py 1.17 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
from django.db import models
from rex.models.university import University
Florent Chehab's avatar
Florent Chehab committed
3
from rex.models.module import Scholarship
Florent Chehab's avatar
Florent Chehab committed
4
from rest_framework import serializers, viewsets, permissions
Florent Chehab's avatar
Florent Chehab committed
5
6
7
8


class UniversityScholarship(Scholarship):
    module_name = "University Scholarship"
Florent Chehab's avatar
Florent Chehab committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    university = models.ForeignKey(
        University, on_delete=models.PROTECT, null=False, related_name="univScholarship")

# API


class UniversityScholarshipSerializer(serializers.ModelSerializer):
    modified_by = serializers.SerializerMethodField()
    modified_date = serializers.SerializerMethodField()

    def get_modified_by(self, obj):
        return obj.modified_by()

    def get_modified_date(self, obj):
        return obj.modified_date()

    class Meta:
        model = UniversityScholarship
27
        fields = ('university', 'modified_by', 'modified_date', 'comment', 'usefull_links',
Florent Chehab's avatar
Florent Chehab committed
28
29
30
31
32
33
34
                  'type', 'currency', 'amount_min', 'amount_max', 'id')


class UniversityScholarshipViewSet(viewsets.ModelViewSet):
    permission_classes = (permissions.DjangoModelPermissions,)
    queryset = UniversityScholarship.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityScholarshipSerializer