recommendation.py 1.35 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from rest_framework import permissions
Florent Chehab's avatar
Florent Chehab committed
3
4
from django.core.validators import MaxValueValidator

5
from backend.models.university import University
6
from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
Florent Chehab's avatar
Florent Chehab committed
7
from backend.models.other_core import Specialty
Florent Chehab's avatar
Florent Chehab committed
8

9
from backend.models.user import RecommendationList
Florent Chehab's avatar
Florent Chehab committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32


class Recommendation(UserRestrictedModule):
    university = models.ForeignKey(University, on_delete=models.PROTECT)
    parent_list = models.ForeignKey(
        RecommendationList, on_delete=models.PROTECT, related_name='recommendations')
    specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT)
    order_in_list = models.PositiveIntegerField()

    comment = models.TextField(null=True, blank=True)
    grade = models.PositiveIntegerField(
        null=True, validators=[MaxValueValidator(20)])

    class Meta:
        unique_together = ('order_in_list', 'parent_list')


class RecommendationSerializer(UserRestrictedModuleSerializer):
    class Meta:
        model = Recommendation
        fields = '__all__'


33
class RecommendationViewSet(UserRestrictedModuleViewSet):
Florent Chehab's avatar
Florent Chehab committed
34
35
36
37
    permission_classes = (permissions.DjangoObjectPermissions,)
    queryset = Recommendation.objects.all()  # pylint: disable=E1101
    serializer_class = RecommendationSerializer
    # TODO PERMISSIOIN