universityTaggedItem.py 965 Bytes
Newer Older
1
from django.db import models
2

3
4
5
6
7
from backend_app.models.abstract.taggedItem import (
    TaggedItem,
    TaggedItemSerializer,
    TaggedItemViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
8
from backend_app.models.university import University
9
from backend_app.permissions.app_permissions import IsOwner
10
11


Florent Chehab's avatar
Florent Chehab committed
12
class UniversityTaggedItem(TaggedItem):
13
    university = models.ForeignKey(
14
15
        University, on_delete=models.PROTECT, related_name="university_tagged_items"
    )
16
17

    class Meta:
18
        unique_together = ("university", "tag", "importance_level")
19
20


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


Florent Chehab's avatar
Florent Chehab committed
27
class UniversityTaggedItemViewSet(TaggedItemViewSet):
28
29
    queryset = UniversityTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = UniversityTaggedItemSerializer
30
    permission_classes = (IsOwner,)
31
32
    end_point_route = "universityTaggedItems"
    filterset_fields = ("university",)