universityInfo.py 1.4 KB
Newer Older
1
from django.db import models
2
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
3
from backend.models.university import University
Florent Chehab's avatar
Florent Chehab committed
4
from backend.models.location import Currency
5
from django.core.validators import MinValueValidator
Florent Chehab's avatar
Florent Chehab committed
6
from backend.utils import get_model_config, get_viewset_permissions
7
8
9


class UniversityInfo(BasicModule):
Florent Chehab's avatar
Florent Chehab committed
10
    model_config = get_model_config("UniversityInfo")
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

    university = models.OneToOneField(
        University, on_delete=models.CASCADE, related_name='university_info', primary_key=True, null=False)

    cost_exchange = models.DecimalField(
        decimal_places=2,
        max_digits=20,
        validators=[MinValueValidator(0)],
        null=True
    )

    cost_double_degree = models.DecimalField(
        decimal_places=2,
        max_digits=20,
        validators=[MinValueValidator(0)],
        null=True
    )

    costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT)

31
32
33
34
    @classmethod
    def get_serializer(cls):
        return UniversityInfoSerializer

35

Florent Chehab's avatar
Florent Chehab committed
36
class UniversityInfoSerializer(BasicModuleSerializer):
37
38
39

    class Meta:
        model = UniversityInfo
Florent Chehab's avatar
Florent Chehab committed
40
        fields = '__all__'
41
42


43
class UniversityInfoViewSet(BasicModuleViewSet):
44
    permission_classes = get_viewset_permissions("UniversityInfoViewSet")
45
46
    queryset = UniversityInfo.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityInfoSerializer