universityTaggedItem.py 1.21 KB
Newer Older
1
from django.db import models
2
from backend.models.abstract.taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
3
from backend.models.university import University
Florent Chehab's avatar
Florent Chehab committed
4
from backend.utils import get_model_config, get_viewset_permissions
5
6


Florent Chehab's avatar
Florent Chehab committed
7
class UniversityTaggedItem(TaggedItem):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("UniversityTaggedItem")
9
10
    university = models.ForeignKey(
        University, on_delete=models.PROTECT, related_name='university_tagged_items')
11
12
13
14
15
16

    @classmethod
    def get_serializer(cls):
        return UniversityTaggedItemSerializer

    class Meta:
17
        unique_together = ('university', 'tag', 'importance_level')
18
19


Florent Chehab's avatar
Florent Chehab committed
20
class UniversityTaggedItemSerializer(TaggedItemSerializer):
21
22
23
24
25
    class Meta:
        model = UniversityTaggedItem
        fields = '__all__'


Florent Chehab's avatar
Florent Chehab committed
26
class UniversityTaggedItemViewSet(TaggedItemViewSet):
27
    permission_classes = get_viewset_permissions("UniversityTaggedItemViewSet")
28
29
    queryset = UniversityTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityTaggedItemSerializer
30
31
32
33
34
35

    BYPASS_DICT_MODE = True

    def extend_queryset(self):
        univ_id = self.kwargs['univ_id']
        return self.my_model_queryset.filter(university__pk=univ_id).distinct()