campusTaggedItem.py 1.15 KB
Newer Older
1
from django.db import models
2
from backend.models.campus import Campus
3
from backend.models.abstract.taggedItem import TaggedItem, TaggedItemSerializer, TaggedItemViewSet
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 CampusTaggedItem(TaggedItem):
Florent Chehab's avatar
Florent Chehab committed
8
    model_config = get_model_config("CampusTaggedItem")
9
10
    campus = models.ForeignKey(
        Campus, on_delete=models.PROTECT, related_name='campus_tagged_items')
11
12
13
14
15
16

    @classmethod
    def get_serializer(cls):
        return CampusTaggedItemSerializer

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


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


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

    BYPASS_DICT_MODE = True

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