campusTaggedItem.py 884 Bytes
Newer Older
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
from backend_app.models.campus import Campus
3 4 5 6 7
from backend_app.models.abstract.taggedItem import (
    TaggedItem,
    TaggedItemSerializer,
    TaggedItemViewSet,
)
8 9


Florent Chehab's avatar
Florent Chehab committed
10
class CampusTaggedItem(TaggedItem):
11

12
    campus = models.ForeignKey(
13 14
        Campus, on_delete=models.PROTECT, related_name="campus_tagged_items"
    )
15 16

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


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


Florent Chehab's avatar
Florent Chehab committed
26
class CampusTaggedItemViewSet(TaggedItemViewSet):
27 28
    queryset = CampusTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = CampusTaggedItemSerializer
29

30
    def get_queryset(self):
31
        campus_id = self.kwargs["campus_id"]
32
        return super().get_queryset().filter(campus=campus_id).distinct()