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

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

8
from backend.models.user import RecommendationList
Florent Chehab's avatar
Florent Chehab committed
9
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
10 11 12


class Recommendation(UserRestrictedModule):
Florent Chehab's avatar
Florent Chehab committed
13
    model_config = get_model_config("Recommendation")
Florent Chehab's avatar
Florent Chehab committed
14 15 16 17 18 19
    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()

20
    comment = models.CharField(default='', blank=True, max_length=5000)
Florent Chehab's avatar
Florent Chehab committed
21 22 23 24 25 26 27 28 29 30 31 32 33
    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__'


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