universityInfo.py 1.43 KB
Newer Older
1
from django.db import models
2
from backend.models.abstract.basic_module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
3
from backend.models.university import University
4
from backend.models.currency 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

    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
    )

29
30
    costs_currency = models.ForeignKey(
        Currency, on_delete=models.PROTECT, default='EUR')
31

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

36

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

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


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