campusTaggedItem.py 896 Bytes
Newer Older
1
2
3
from django.db import models
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.university import Campus
Florent Chehab's avatar
Florent Chehab committed
4
from backend.models.tag import Tag
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


class CampusTaggedItem(BasicModule):
    campus = models.OneToOneField(
        Campus, on_delete=models.PROTECT, related_name='city_items', primary_key=True)
    tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)

    @classmethod
    def get_serializer(cls):
        return CampusTaggedItemSerializer

    class Meta:
        unique_together = ('campus', 'tag')


class CampusTaggedItemSerializer(BasicModuleSerializer):
    class Meta:
        model = CampusTaggedItem
        fields = '__all__'


class CampusTaggedItemViewSet(BasicModuleViewSet):

    queryset = CampusTaggedItem.objects.all()  # pylint: disable=E1101
    serializer_class = CampusTaggedItemSerializer