exchangeFeedback.py 1.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator

from backend_app.models.abstract.essentialModule import (
    EssentialModule,
    EssentialModuleSerializer,
    EssentialModuleViewSet,
)
from backend_app.models.exchange import Exchange
10
from backend_app.serializers import ExchangeSerializer
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from backend_app.models.university import University


class ExchangeFeedback(EssentialModule):
    university = models.ForeignKey(University, on_delete=models.PROTECT, default=0)
    exchange = models.OneToOneField(
        Exchange,
        on_delete=models.CASCADE,
        related_name="feedbacks",
        primary_key=True,
        null=False,
        default=0,
    )
    general_comment = models.TextField(null=True, max_length=1500)
    academical_level_appreciation = models.IntegerField(
        validators=[MaxValueValidator(5), MinValueValidator(-5)]
    )
    foreign_student_welcome = models.PositiveIntegerField(
        validators=[MaxValueValidator(10)]
    )
    cultural_interest = models.PositiveIntegerField(validators=[MaxValueValidator(10)])


class ExchangeFeedbackSerializer(EssentialModuleSerializer):
35
36
    exchange = ExchangeSerializer(read_only=True)

37
38
39
40
41
42
    class Meta:
        model = ExchangeFeedback
        fields = "__all__"


class ExchangeFeedbackViewSet(EssentialModuleViewSet):
43
44
45
46
47
    queryset = ExchangeFeedback.objects.all().prefetch_related(
        "exchange",
        "exchange__exchange_courses",
        "exchange__exchange_courses__course_feedback",
    )  # pylint: disable=E1101
48
49
    serializer_class = ExchangeFeedbackSerializer
    end_point_route = "exchangeFeedbacks"
50
    filterset_fields = ("university",)